// Handle SMSG_SPELL_CAST_RESULT packet private static void HandleSpellCastResult(Packet packet, ClientGame game) { SpellCastResult result = (SpellCastResult)packet.ReadByte(); if (result != SpellCastResult.Success) { game.SetActiveCardActionGrid(true); game.Chat.Write(result.GetDescription(), ChatTypes.Info); return; } var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 5, 7, 0, 1, 4, 3, 2, 6); var mana = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(guid, 7, 2); var manaCost = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(guid, 4, 0, 1); var player = game.GetPlayer(packet.ReadUInt32()); var spellId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guid, 3, 6, 5); player.HandleSuccessfulSpellCast(guid, spellId, mana, manaCost); }
// Handle SMSG_DECK_CARDS packet private static void HandleDeckCards(Packet packet, ClientGame game) { var cardsCount = packet.ReadByte(); var guids = new PacketGuid[cardsCount]; for (var i = 0; i < cardsCount; i++) { guids[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids[i], 7, 2, 1, 4, 5, 0, 6, 3); } var player = game.GetPlayer(packet.ReadUInt32()); if (player == null) { return; } for (var i = 0; i < cardsCount; i++) { packet.ReadGuidByteStreamInOrder(guids[i], 2, 1, 7, 6, 0, 5, 3, 4); } player.PutCardsOnDeck(Array.ConvertAll(guids, guid => (UInt64)guid)); }
// Handle SMSG_SPELL_DRAIN private static void HandleSpellDrain(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 0, 1, 2, 3, 4, 5, 6, 7); var isAlive = packet.ReadBit(); var player = game.GetPlayer(packet.ReadUInt32()); var opponent = game.GetOpponent(player.Id); packet.ReadGuidByteStreamInOrder(guid, 0, 1, 2, 3, 4, 5, 6, 7); var drainedHealth = packet.ReadByte(); var restoredHealth = packet.ReadByte(); var drainedMana = packet.ReadByte(); var restoredMana = packet.ReadByte(); var opponentMana = packet.ReadByte(); var health = packet.ReadByte(); var mana = packet.ReadByte(); if (isAlive) { opponent.AttackCard(guid, drainedHealth, CombatLogTypes.SpellUsage, true); opponent.SetCardMana(guid, opponentMana); } else { opponent.DestroyCard(guid, packet.ReadByte(), CombatLogTypes.SpellUsage, true); } var currentCardGuid = player.ActiveCard.Guid; player.HealCard(currentCardGuid, health, restoredHealth); player.SetCardMana(currentCardGuid, mana); }
// Handle SMSG_SPELL_DAMAGE packet private static void HandleSpellDamage(Packet packet, ClientGame game) { var targetsCount = packet.ReadByte(); var targets = new PacketGuid[targetsCount]; var isAlive = new bool[targetsCount]; for (int i = 0; i < targetsCount; i++) { targets[i] = new PacketGuid(); isAlive[i] = packet.ReadBit(); packet.ReadGuidBitStreamInOrder(targets[i], 6, 3, 1, 7, 0, 2, 5, 4); } var opponent = game.GetOpponent(packet.ReadUInt32()); for (int i = 0; i < targetsCount; i++) { packet.ReadGuidByteStreamInOrder(targets[i], 4, 3, 5); byte damage = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(targets[i], 2, 0, 1, 6, 7); if (isAlive[i]) { opponent.AttackCard(targets[i], damage, CombatLogTypes.SpellUsage, false); } else { opponent.DestroyCard(targets[i], damage, CombatLogTypes.SpellUsage, false); } } }
// Handle SMSG_ATTACK_RESULT packet private static void HandleAttackResult(Packet packet, Game game) { var result = (AttackResult)packet.ReadByte(); if (result == AttackResult.InvalidTarget) { game.IsGameWaiting = false; game.OnErrorOccured(Texts.InvalidTarget); return; } var cardGuid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(cardGuid, 6, 2, 1, 7, 3, 0, 4, 5); packet.ReadGuidByteStreamInOrder(cardGuid, 2, 6, 7); var attackerId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(cardGuid, 1, 3, 0); var damage = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(cardGuid, 5, 4); var opponent = game.GetOpponent(attackerId); if (result == AttackResult.CardAttacked) { opponent?.AttackCard(cardGuid, damage, CombatLogType.BasicDamage, false); } else { opponent?.DestroyCard(cardGuid, damage, CombatLogType.BasicDamage, false); } }
// Handle SMSG_ATTACK_RESULT packet private static void HandleAttackResult(Packet packet, ClientGame game) { var result = (AttackResult)packet.ReadByte(); if (result == AttackResult.InvalidTarget) { game.SetActiveCardActionGrid(true); game.Chat.Write("You cannot attack that target", ChatTypes.Info); return; } else { var cardGuid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(cardGuid, 6, 2, 1, 7, 3, 0, 4, 5); packet.ReadGuidByteStreamInOrder(cardGuid, 2, 6, 7); var attackerId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(cardGuid, 1, 3, 0); var damage = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(cardGuid, 5, 4); var opponent = game.GetOpponent(attackerId); if (result == AttackResult.CardAttacked) { opponent.AttackCard(cardGuid, damage, CombatLogTypes.BasicDamage, false); } else { opponent.DestroyCard(cardGuid, damage, CombatLogTypes.BasicDamage, false); } } }
// Handle SMSG_SPELL_CAST_RESULT packet private static void HandleSpellCastResult(Packet packet, Game game) { var result = (SpellCastResult)packet.ReadByte(); if (result != SpellCastResult.Success && result != SpellCastResult.SuccessContinueMove) { game.IsGameWaiting = false; game.OnErrorOccured(result.GetDescription()); return; } var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 5, 7, 0, 1, 4, 3, 2, 6); var mana = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(guid, 7, 2); var manaCost = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(guid, 4, 0, 1); var player = game.GetPlayer(packet.ReadUInt32()); var spellId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guid, 3, 6, 5); player.HandleSuccessfulSpellCast(guid, spellId, mana, manaCost); }
// Handle SMSG_SELECT_CARDS packet private static void HandleSelectCards(Packet packet, ClientGame game) { game.MainWindow.SlideShow.SetVisible(false); game.ShowCardDeck(true); var count1 = packet.ReadByte(); var count2 = packet.ReadByte(); var guids1 = new PacketGuid[count1]; var guids2 = new PacketGuid[count2]; for (var i = 0; i < count2; i++) { guids2[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids2[i], 1, 2, 7, 0, 5, 3, 4, 6); } for (var i = 0; i < count1; i++) { guids1[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids1[i], 7, 1, 2, 4, 6, 0, 3, 5); } var senderId = packet.ReadUInt32(); var player1 = (game.Player.Id == senderId) ? game.Player : game.Opponent; var player2 = (game.Player.Id == senderId) ? game.Opponent : game.Player; var cards1 = new PlayableCard[count1]; var cards2 = new PlayableCard[count2]; for (var i = 0; i < count1; i++) { packet.ReadGuidByteStreamInOrder(guids1[i], 7, 2, 0, 1, 6, 4, 5); var id = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guids1[i], 3); cards1[i] = PlayableCard.Create(guids1[i], DataHolder.GetCard(id)); } for (var i = 0; i < count2; i++) { packet.ReadGuidByteStreamInOrder(guids2[i], 4, 2, 6, 1, 7, 0); var id = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guids2[i], 3, 5); cards2[i] = PlayableCard.Create(guids2[i], DataHolder.GetCard(id)); } player1.AddCards(cards1); player2.AddCards(cards2); game.UnloadData(); game.Chat.Write("Game has started", ChatTypes.Info); }
// Handle SMSG_APPLY_AURA packet private static void HandleApplyAura(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 7, 2, 1, 3, 5, 4, 0, 6); var player = game.GetPlayer(packet.ReadUInt32()); packet.ReadGuidByteStreamInOrder(guid, 0, 5, 2, 1, 7, 6, 4, 3); var spellId = packet.ReadUInt32(); player.ApplyAura(guid, spellId); }
// SMSG_SPELL_AURA_EXPIRED private static void HandleSpellAuraExpired(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 0, 5, 7, 2, 1, 4, 3, 6); var spellId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guid, 7, 6, 5, 4, 3, 2, 1, 0); var player = game.GetPlayer(packet.ReadUInt32()); player.ExpireAura(guid, spellId); }
// Handle SMSG_ACTIVE_PLAYER packet private static void HandleActivePlayer(Packet packet, Game game) { var cardGuid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(cardGuid, 7, 1, 2, 0, 3, 5, 4, 6); packet.ReadGuidByteStreamInOrder(cardGuid, 7, 5, 4, 2, 6); var activePlayerId = packet.ReadUInt32(); var activePlayer = game.GetPlayer(activePlayerId); packet.ReadGuidByteStreamInOrder(cardGuid, 1, 0, 3); game.IsGameWaiting = game.Player != activePlayer; activePlayer.SetActiveCard(cardGuid); }
// Handle SMSG_CARD_HEALED packet private static void HandleCardHealed(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 7, 2, 6, 1, 3, 0, 5, 4); packet.ReadGuidByteStreamInOrder(guid, 5, 2, 7, 1); var player = game.GetPlayer(packet.ReadUInt32()); var health = packet.ReadByte(); packet.ReadGuidByteStreamInOrder(guid, 4, 0, 3, 6); var amount = packet.ReadByte(); player.HealCard(guid, health, amount); }
// Handle SMSG_SELECT_CARDS packet private static void HandleSelectCards(Packet packet, Game game) { game.IsGameWaiting = false; var count1 = packet.ReadByte(); var count2 = packet.ReadByte(); var guids1 = new PacketGuid[count1]; var guids2 = new PacketGuid[count2]; for (var i = 0; i < count2; i++) { guids2[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids2[i], 1, 2, 7, 0, 5, 3, 4, 6); } for (var i = 0; i < count1; i++) { guids1[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids1[i], 7, 1, 2, 4, 6, 0, 3, 5); } var senderId = packet.ReadUInt32(); var player1 = (game.Player.Id == senderId) ? game.Player : game.Opponent; var player2 = (game.Player.Id == senderId) ? game.Opponent : game.Player; var cards1 = new PlayableCard[count1]; var cards2 = new PlayableCard[count2]; for (var i = 0; i < count1; i++) { packet.ReadGuidByteStreamInOrder(guids1[i], 7, 2, 0, 1, 6, 4, 5); var id = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guids1[i], 3); cards1[i] = PlayableCard.Create(guids1[i], game.DataHolder.GetCard(id), player1); } for (var i = 0; i < count2; i++) { packet.ReadGuidByteStreamInOrder(guids2[i], 4, 2, 6, 1, 7, 0); var id = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guids2[i], 3, 5); cards2[i] = PlayableCard.Create(guids2[i], game.DataHolder.GetCard(id), player2); } player1.SetCards(cards1); player2.SetCards(cards2); }
// Handle SMSG_CARD_STAT_CHANGED packet private static void HandleCardStatChanged(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 2, 6, 7, 1, 0, 3, 5, 4); packet.ReadGuidByteStreamInOrder(guid, 5, 7); var value = packet.ReadSByte(); packet.ReadGuidByteStreamInOrder(guid, 6, 3, 1); var playerId = packet.ReadUInt32(); packet.ReadGuidByteStreamInOrder(guid, 0, 4, 2); var cardStat = (CardStats)packet.ReadByte(); game.GetPlayer(playerId).ModifyCardStat(guid, cardStat, value); }
// Handle SMSG_ACTIVE_PLAYER packet private static void HandleActivePlayer(Packet packet, ClientGame game) { var cardGuid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(cardGuid, 7, 1, 2, 0, 3, 5, 4, 6); packet.ReadGuidByteStreamInOrder(cardGuid, 7, 5, 4, 2, 6); var activePlayerId = packet.ReadUInt32(); var activePlayer = (game.Player.Id == activePlayerId) ? game.Player : game.Opponent; var nonActivePlayer = (game.Player.Id == activePlayerId) ? game.Opponent : game.Player; packet.ReadGuidByteStreamInOrder(cardGuid, 1, 0, 3); nonActivePlayer.SetWaitingState(); activePlayer.SetActiveState(cardGuid); game.SetActiveCardActionGrid(game.Player.Id == activePlayerId); }
// Handle SMSG_SPELL_PERIODIC_DAMAGE packet private static void HandleSpellPeriodicDamage(Packet packet, ClientGame game) { var guid = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guid, 6, 4, 1); var isAlive = packet.ReadBit(); packet.ReadGuidBitStreamInOrder(guid, 7, 2, 3, 5, 0); var player = game.GetPlayer(packet.ReadUInt32()); packet.ReadGuidByteStreamInOrder(guid, 0, 1, 2, 3, 7, 5, 4, 6); byte damage = packet.ReadByte(); if (isAlive) { player.AttackCard(guid, damage, CombatLogTypes.SpellUsage, true); } else { player.DestroyCard(guid, damage, CombatLogTypes.SpellUsage, true); } }
// Handle SMSG_MANA_REPLENISHMENT packet private static void HandleManaReplenishment(Packet packet, ClientGame game) { var cardCount = packet.ReadByte(); var guids = new PacketGuid[cardCount]; for (var i = 0; i < cardCount; i++) { guids[i] = new PacketGuid(); packet.ReadGuidBitStreamInOrder(guids[i], 5, 0, 1, 2, 3, 7, 4, 6); } var player = game.GetPlayer(packet.ReadUInt32()); var manaReplenished = packet.ReadByte(); for (var i = 0; i < cardCount; i++) { packet.ReadGuidByteStreamInOrder(guids[i], 2, 6, 0, 7, 1, 4, 3, 5); var mana = packet.ReadByte(); player.SetCardMana(guids[i], mana); } game.Chat.LogManaReplenishment(player, manaReplenished); }