Example #1
0
        // 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);
        }
Example #2
0
        // 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_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));
        }
Example #4
0
        // 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);
        }
Example #5
0
 public GHTextPage(GamePage gamePage, List <GHPutStrItem> list)
 {
     InitializeComponent();
     _gamePage            = gamePage;
     _clientGame          = _gamePage.ClientGame;
     TextView.ItemsSource = list;
 }
        // 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);
                }
            }
        }
Example #7
0
 public GetLinePage(GamePage gamePage, string query)
 {
     InitializeComponent();
     _gamePage         = gamePage;
     _clientGame       = gamePage.ClientGame;
     labelCaption.Text = query;
 }
Example #8
0
 // Update is called once per frame
 void Update()
 {
     if (client == null)
     {
         client = GameObject.FindObjectOfType <ClientGame> ();
     }
 }
Example #9
0
        // Handle SMSG_INIT_RESPONSE packet
        private static void HandleInitResponse(Packet packet, ClientGame game)
        {
            var hasOpponent = packet.ReadBit();
            var playerId    = packet.ReadUInt32();

            game.Player.Id = playerId;

            string message;

            if (hasOpponent)
            {
                var opponentId   = packet.ReadUInt32();
                var opponentName = packet.ReadString();
                message = $"{opponentName} has joined the game";

                game.Opponent.Id   = opponentId;
                game.Opponent.Name = opponentName;
            }
            else
            {
                message = "Waiting for another player to join the game";
            }

            game.Chat.Write(message, ChatTypes.Info);
        }
Example #10
0
 public NamePage(GamePage gamepage)
 {
     InitializeComponent();
     ValidationExpression = new Regex(@"^[A-Za-z0-9_]{1,32}$");
     _clientGame          = gamepage.ClientGame;
     _gamePage            = gamepage;
 }
Example #11
0
        // Handle SMSG_CHAT_MESSAGE packet
        private static void HandleChatMessage(Packet packet, ClientGame game)
        {
            var chatType   = (ChatTypes)packet.ReadByte();
            var senderName = packet.ReadString();
            var message    = packet.ReadString();

            game.Chat.WriteChannelMessage(chatType, message, senderName);
        }
Example #12
0
 public ProjectG(TcpClient tcp) : base(tcp)
 {
     ServerType      = ServerTypeEnum.Login;
     PacketLogin     = new ClientLogin();
     PacketGame      = new ClientGame();
     PacketMessenger = new ClientMessanger();
     Commands        = new ChatCommands();
 }
Example #13
0
        public void joinToGameAndWithTooMuchMoney()
        {
            pref = new GamePreferences(8, 2, 5, 10, 1, 2, 3, true);
            ClientGame game = gc.createGame(pref, username);

            Assert.Null(gc.joinGame(game.getID(), username, 999));
            game.Players.Remove(us.getUser(username));
        }
Example #14
0
        public void removePlayerTest()
        {
            pref = new GamePreferences(8, 2, 5, 10, 1, 2, 3, true);
            ClientGame game = gc.createGame(pref, username);

            gc.joinGame(game.getID(), username, 3);
            Assert.NotNull(gameService.removePlayer(username, game.getID()));
            Assert.False(game.Players.Contains(us.getUser(username)));
        }
        public static GameObject Construct(Type type, ClientGame game, int id)
        {
            object[] constuctorParams = new object[1];
            constuctorParams[0] = game;
            GameObject obj = (GameObject)constructorDictionary[type].Invoke(constuctorParams);

            obj.ID = id;
            return(obj);
        }
Example #16
0
        public void valid_spectateGame()
        {
            ClientGame    g = gc.getAllSpectatingGames()[0];
            int           NumberOfPlayersBefore = g.Spectators.Count;
            List <string> spec = null;

            Assert.NotNull(spec = gc.spectateGame(g.getID(), "abc"));
            Assert.AreEqual(NumberOfPlayersBefore + 1, spec.Count);
        }
Example #17
0
 public GameWindow()
 {
     InitializeComponent();
     Title             = (string)Application.Current.Resources["gameName"];
     game              = (ClientGame)Application.Current.Resources["clientGame"];
     game.OnMapChange += (_, __) => PlaceObjects(GUIMap, game.Map);
     game.HumansWin   += (_, __) => MessageBox.Show("Humans have survived, and all zombies are dead.  Humans win!\n" + MakeScoreboard(), "Victory for Humans!");
     game.ZombiesWin  += (_, __) => MessageBox.Show("Zombies have killed all the humans.  Zombies win!\n" + MakeScoreboard(), "Victory for Zombies!");
     game.Draw        += (_, __) => MessageBox.Show("Tragically, neither zombies nor humans survived.\n" + MakeScoreboard(), "It's a draw.");
 }
Example #18
0
 public void PushPMMessage(int gameId, string sender, string message)
 {
     Dispatcher.CurrentDispatcher.InvokeAsync(() =>
     {
         ClientGame game = findGame(gameId);
         game.AddMessage(sender, message);
         GameFrame gameFrame = findGameFrame(gameId);
         gameFrame.GamePM.PushMessage(sender);
     });
 }
Example #19
0
 public void PlayerQuitGame(string player, int gameId)
 {
     Dispatcher.CurrentDispatcher.InvokeAsync(() =>
     {
         GameFrame gameFrame = findGameFrame(gameId);
         ClientGame cg       = findGame(gameId);
         gameFrame.RemovePlayer(player);
         cg.RemovePlayer(player);
     });
 }
Example #20
0
        private void HandleDoubleClick(object sender, RoutedEventArgs e)
        {
            cl.SetCurrSearchScreen(this);
            ClientGame selectedGame = (ClientGame)listView.SelectedItem;

            if (selectedGame != null)
            {
                currRoomId = selectedGame.roomId;
                cl.JoinTheGame(currRoomId, selectedGame.startingChip);
            }
        }
Example #21
0
        public void valid_gameListByName()
        {
            ClientGame g = gc.getActiveGames("preferences", prefs, "abc")[0];;

            Assert.NotNull(gc.joinGame(g.getID(), "ohad", 30));

            List <ClientGame> games = gc.getActiveGames("playerName", "ohad", "abc");

            Assert.AreEqual(1, games.Count);
            //Assert.True(games[0].GetUserProfiles().Contains(userProf));s
        }
Example #22
0
File: GameAPI.cs Project: cynic/HvZ
 private void initializeGameWindow(string gameName)
 {
     app.Resources["gameName"] = gameName;
     try {
         clientGame = new ClientGame(gameName, server, port);
     } catch (System.Net.Sockets.SocketException) {
         throw new Exception("The game server has crashed (I can't connect to it, anyway...)! Find your lecturer and tell him. He'll restart it for you.");
     }
     app.Resources["clientGame"] = clientGame;
     g = new GameWindow(); // ... which uses the Resources I've just set up...
 }
Example #23
0
        public ClientGame AddGame(Game game)
        {
            if (!GameIdIsUnique(game.ID.ToString()))
            {
                return(null);
            }
            var lg = new ClientGame(game);

            _games.Add(game.ID.ToString(), lg);
            return(lg);
        }
Example #24
0
        public void joinGameTwiceTest()
        {
            ClientGame game = gc.createGame(pref, username);

            Assert.AreEqual(0, game.Players.Count);
            List <String> users = gc.joinGame(game.getID(), username, 50);

            gc.joinGame(game.getID(), username, 60);
            Assert.AreEqual(1, users.Count);
            Assert.True(users.Contains(us.getUser(username).Username));
        }
Example #25
0
        public void removeUnExistedPlayer()
        {
            pref = new GamePreferences(8, 2, 5, 10, 1, 2, 3, true);
            ClientGame game = gc.createGame(pref, username);

            gc.joinGame(game.getID(), username, 100);
            Assert.Throws(typeof(InvalidOperationException), delegate
            {
                gameService.removePlayer("Moshe", game.getID());
            }
                          );
        }
Example #26
0
        public void joinGameTest()
        {
            pref = new GamePreferences(8, 2, 5, 10, 1, 2, 3, true);
            ClientGame game = gc.createGame(pref, username);

            Assert.AreEqual(0, game.Players.Count);

            List <String> users = gc.joinGame(game.getID(), username, 50);

            Assert.AreEqual(1, users.Count);
            Assert.True(users.Contains(us.getUser(username).Username));
        }
Example #27
0
        public ClientGame createGame(GamePreferences preferecnces)
        {
            if (!AuthManager.Instance.containsConnection(Context.ConnectionId))
            {
                return(null);
            }
            string            userName = AuthManager.Instance.GetNameByConnectionId(Context.ConnectionId);
            GameCenterService gc       = new GameCenterService();
            ClientGame        game     = gc.createGame(preferecnces, userName);

            return(game);
        }
Example #28
0
 internal void AddGame(string gameOwnerName)
 {
     lock (Games)
     {
         if (!Games.ContainsKey(gameOwnerName))
         {
             ClientGame game = new ClientGame(gameOwnerName);
             game.Lobby = this;
             Games.Add(gameOwnerName, game);
         }
     }
 }
        // 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);
        }
Example #30
0
        // 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);
        }
Example #31
0
        // 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);
        }
Example #32
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game"></param>
        public MapScroller(ClientGame game, GameState state)
        {
            RegisterListeners();
            characterAvailable = true;
            _game = game;
            _module = state.Module;
            _iso = _module.Map.Iso;
            _state = state;
            _spriteBatch = game.SpriteBatch;
            _gameFont = game.Content.Load<SpriteFont>("Fonts//gameFont");
            _circle = _game.Content.Load<Texture2D>("Textures//circle");
            _screenSpace = new Rectangle(0, 0, _game.GraphicsDevice.PresentationParameters.BackBufferWidth, _game.GraphicsDevice.PresentationParameters.BackBufferHeight);

            //  World space
            var max = _iso.TilePlotter(new Point(_module.Map.Width - 1, _module.Map.Height - 1));
            _worldSpace = new Rectangle(0, 0, max.X + _module.Map.TileWidth, max.Y + _module.Map.TileHeight);
            //  Anchor space
            _anchorSpace = _worldSpace;
            var horizontal = _screenSpace.Right - _screenSpace.Left;
            _anchorSpace.Width -= horizontal;
            if (_anchorSpace.Right < _anchorSpace.Left)
                _anchorSpace.Width = 0;
            var vertical = _screenSpace.Bottom - _screenSpace.Top;
            _anchorSpace.Height -= vertical;
            if (_anchorSpace.Bottom < _anchorSpace.Top)
                _anchorSpace.Height = 0;
            //  Adjust for staggered maps to eliminate jaggies when scrolling to map edge
            if (_iso.Style == IsometricStyle.Staggered)
            {
                _anchorSpace.Y += _module.Map.TileHeight / 2;
                _anchorSpace.Height -= _module.Map.TileHeight / 2;

                _anchorSpace.X += _module.Map.TileWidth / 2;
                _anchorSpace.Width -= _module.Map.TileWidth / 2;

                _screenAnchor = new Point(_anchorSpace.Left, _anchorSpace.Top);
            }
            else
            {
                //  Screen anchor
                _screenAnchor = new Point(0, 0);
            }

        }
Example #33
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (_content == null)
                _content = new ContentManager(ScreenManager.Game.Services, "Content");

            //  Add all components local to this screen

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
            _eventManager.QueueEvent(new GameEvent(EventType.GetReady));
            _game = (ClientGame)ScreenManager.Game;
            _agent = _game.Agent;
            _gameState = _game.GameState;
            _ui = _game.UI;
            _ui.LoadFile("Content\\html\\lobby.html");
            _ui.WebView.LoadCompleted += WebViewLoadCompleted;
        }