Beispiel #1
0
        public void StartTurnRequesterThread()
        {
            RequestNextTurn     = false;
            turnRequesterThread = new Thread(() =>
            {
                while (true)
                {
                    lock (MobileList)
                    {
                        if (TerminateThreads)
                        {
                            break;
                        }

                        if (RequestNextTurn && MobileList.Find(x => x.Movement.IsFalling && x.IsAlive) == null)
                        {
                            RequestNextTurn = false;
                            ServerInformationHandler.RequestNextPlayerTurn(CurrentTurnOwnerDamageDealt);
                            CurrentTurnOwnerDamageDealt = null;
                        }
                    }

                    Thread.Sleep(1000);
                }
            });
            turnRequesterThread.Name         = "Turn Requester Thread";
            turnRequesterThread.IsBackground = true;
            turnRequesterThread.Start();
        }
Beispiel #2
0
        //MatchMetadata matchMetadata;

        public GameRoom()
        {
            animatedButtonList = new List <AnimatedButton>();
            buttonList         = new List <Button>();
            spriteList         = new List <Sprite>();

            //Background
            Background = new Sprite(@"Interface/InGame/Scene/GameRoom/Background",
                                    position: Parameter.ScreenCenter,
                                    layerDepth: DepthParameter.Foreground,
                                    shouldCopyAsset: false);

            //UI Components
            CreatePlayerButton();
            CreateMiddleBarAnimatedButtons();
            CreateBottomBarAnimatedButtons();
            CreateMatchMetadataButtons();
            CreateRoomName();
            CreateMobilePortrait();

            //text box
            textBox = new TextBox(new Vector2(-391, 139), new Vector2(410, 135), 100, 0,
                                  hasScrollBar: true, scrollBackgroundAlpha: 0.6f,
                                  hasTextField: true, textFieldBackground: 0, textFieldOffset: new Vector2(30, -1), maximumTextLength: 50,
                                  onSendMessage: OnSendMessage);

            textBox.EnableTextField();

            matchConfigurationGrid = new MatchConfigurationGrid(Parameter.ScreenCenter - new Vector2(-1, 115));

            ServerInformationBroker.Instance.ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomRefreshMetadata] += UpdateRoomMetadataAsyncCallback;
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerRoomLeaveRoom, LeaveRoomAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerRoomReadyRoom, ReadyRoomAsyncCallback);

            //Textual callbacks
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerChatSendPlayerMessage, OnReceiveMessageAsyncCallback);
            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerChatSendSystemMessage, OnReceiveMessageAsyncCallback);

            playerButtonList.UpdatePlayerButtonList();

            //Popup menus
            popupSelectMobile = new PopupSelectMobile(SelectMobileAction, CloseSelectMobileAction);
            PopupHandler.Add(popupSelectMobile);

            PopupHandler.PopupGameOptions.OnClose = OptionsCloseAction;

            popupSelectItem          = new PopupSelectItem();
            popupSelectItem.OnClose += SelectItemCloseAction;

            //Connect to channel
            ServerInformationHandler.SendChatDisconnectionRequest();
            ServerInformationHandler.SendChatConnectionRequest(Message.BuildGameServerChatGameRoom(GameInformation.Instance.RoomMetadata.ID));

            #warning Pre-release deactivation
            animatedButtonList[2].Disable();
            animatedButtonList[5].Disable();
            animatedButtonList[6].Disable();
            animatedButtonList[8].Disable();
            buttonList.Remove(metadataRenameRoom);
        }
Beispiel #3
0
 private void ExitDoorAction(object sender)
 {
     //Sends the server information about the attributes and equipped avatars
     ServerInformationHandler.AvatarShopUpdatePlayerData();
     SceneHandler.Instance.RequestSceneChange(SceneType.GameList, TransitionEffectType.RotatingRectangles);
     ((AnimatedButton)sender).Disable(true);
 }
Beispiel #4
0
        public static void LobbyServiceHUB(ExtendedConcurrentQueue <byte[]> provider, string[] request, Dictionary <int, object> paramDictionary)
        {
            int    service = int.Parse(request[0]);
            object answer  = null;

            switch (service)
            {
            case NetworkObjectParameters.LobbyServerPlayerUIDRequest:
                answer = PlayerHandler.GenerateUIDForPlayerLogin(request[1]);
                break;

            case NetworkObjectParameters.LobbyServerLoginRequest:
                answer = PlayerHandler.LobbyLoginRequest(request[1]);
                break;

            case NetworkObjectParameters.GameServerRegisterRequest:
                answer = ServerInformationHandler.RefreshGameServerStatusRequest(request[1], paramDictionary);
                break;

            case NetworkObjectParameters.LobbyServerServerListRequest:
                ServerInformationHandler.GameServerListRequest(provider);
                return;
            }

            provider.Enqueue(service, answer);
        }
Beispiel #5
0
        //Remove param and adjust it properly
        public void UpdateLoadingPercentage(int accumulator)
        {
            if (accumulator > 100 || accumulator == lastSend)
            {
                return;
            }

            lock (playerButtonList)
            {
                if (playerButtonList.UserLoadingButton == null)
                {
                    return;
                }

                playerButtonList.UserLoadingButton.UpdatePercentage(accumulator);
            }

            lastSend = accumulator;

            //if (accumulator % 5 != 0)
            ServerInformationHandler.UpdateLoadingScreenPercentage(accumulator);

            if (accumulator == 100)
            {
                ServerInformationHandler.ClientReadyToStartGame();
                hasStarted = true;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Sends the server a request for purchasing the selected avatar
        /// in gold, closes <see cref="popupBuyAvatar">. The confirmation
        /// occurs after the server process the request and a popup will show up.
        /// With the confirmation status.
        /// </summary>
        public void OnBuyGold(object sender)
        {
            //send request
            ServerInformationHandler.AvatarShopBuyAvatarGold(selectedAvatarMetadata);
            PopupHandler.Remove(popupBuyAvatar);

            buyButton.Disable(true);
            tryButton.Disable(true);
        }
Beispiel #7
0
        private void ChangeTeamAction(object sender)
        {
            AnimatedButton b = (AnimatedButton)sender;

            b.Disable();
            b.OnDisabled = (a) => { b.Enable(); };

            ServerInformationHandler.ChangeTeam();
        }
Beispiel #8
0
        // HUBS
        public void LobbyServerConsumerAction(ClientServiceProvider csp, string[] request)
        {
            int service = int.Parse(request[0]);

            switch (service)
            {
            case NetworkObjectParameters.LobbyServerServerListRequest:
                ServerInformationHandler.ServerListHandle(request[1]);
                break;
            }
        }
Beispiel #9
0
        public virtual void RequestUseItem(ItemType itemType)
        {
            //Send message to srv
            SyncMobile.UsedItem = itemType;

#if !DEBUGSCENE
            ServerInformationHandler.SynchronizeItemUsage(SyncMobile);
#else
            UseItem(itemType);
#endif
        }
Beispiel #10
0
        public void RequestLoseTurn()
        {
            LoseTurn();

            SyncMobile.Delay += NetworkObjectParameters.TurnSkipDelayCost;

            if (IsPlayable)
            {
                LevelScene.HUD.Delayboard.ComputeDelay();
                ServerInformationHandler.RequestLoseTurn(SyncMobile);
            }
        }
Beispiel #11
0
        public void RequestDeath(CausaMortis causaMortis)
        {
#if !DEBUGSCENE
            if (causaMortis == CausaMortis.Bungee)
            {
                LevelScene.CurrentTurnOwnerDamageDealt.AddEntry(Owner.ID,
                                                                0, 0, 0, true, new int[] { 0, 0 }, new int[] { 0, 0 },
                                                                Facing.Left, new HashSet <WeatherType>());
            }

            SyncMobile.CausaMortis = causaMortis;
            SyncMobile.IsAlive     = false;
            ServerInformationHandler.RequestDeath(SyncMobile);
#endif
        }
Beispiel #12
0
        public void RequestShoot()
        {
            //Prepare the function
            SyncMobile.SyncProjectile = new SyncProjectile();
            SyncMobile.SyncProjectile.ShotStrenght   = LevelScene.HUD.StrenghtBar.Intensity;
            SyncMobile.SyncProjectile.ShotType       = SelectedShotType;
            SyncMobile.SyncProjectile.ShotAngle      = Crosshair.GetProjectileTrajetoryAngle();
            SyncMobile.SyncProjectile.CannonPosition = Crosshair.CannonPosition.ToArray <float>();
            SyncMobile.RemoveSynchronizableAction(SynchronizableAction.ChargingShot);
            SyncPosition = Position;
            UpdateSyncMobileToServer();

#if !DEBUGSCENE
            ServerInformationHandler.RequestShot(SyncMobile);
#else
            ConsumeShootAction(SyncMobile);
#endif

            LoseTurn();
        }
Beispiel #13
0
        public override void Initialize(GraphicsDevice GraphicsDevice, SpriteBatch SpriteBatch)
        {
            base.Initialize(GraphicsDevice, SpriteBatch);

            //Initializing HUD component
            HUD = new HUD(ownedMobile, MobileList);

            //Extract terrain geography
            Topography.Initialize(Foreground);

            MobileList.ForEach((x) =>
            {
                //Repositioning the actors in order to accurately reproduce the scenario coordinate showed in the loading screen
                //This must be called here because in this position the background will be already initialized
                x.Position -= Foreground.Pivot;

                //Define the spawning points for each remote mobile
                if (!x.IsPlayable)
                {
                    ((RemoteMovement)x.Movement).DesiredPosition = x.Position;
                }
            });

            //Start all mobiles facing trajectory
            StartMobileFacingTrajectory();

            //Parallax Vectors
            BackgroundRemainingImage = new Vector2(Background.SpriteWidth, Background.SpriteHeight) - Parameter.ScreenResolution;

            //Clear all sfx from the list
            SpecialEffectHandler.Initialize();

            //Clear all pending death animations
            DeathAnimation.Initialize();

            //Start Match
#if !DEBUGSCENE
            ServerInformationHandler.StartMatch();
#endif
        }
Beispiel #14
0
        public ServerSelection()
        {
            ServerInformationHandler.RequestServerList();

            Background = new Sprite(@"Interface/InGame/Scene/ServerList/Background",
                                    position: Parameter.ScreenCenter,
                                    layerDepth: DepthParameter.Background,
                                    shouldCopyAsset: false);

            //Must change exit door position on gamelist as well
            exitDoor = AnimatedButtonBuilder.BuildButton(
                AnimatedButtonType.ExitDoor,
                Parameter.ScreenCenter + new Vector2(-330, 265),
                (sender) =>
            {
                SceneHandler.Instance.CloseGame();
            });

            serverButtonList = new List <ServerButton>();

            ServerInformationBroker.Instance.ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerPlayerAccessRequest, ChangeScene);
        }
Beispiel #15
0
        public void UpdateServerButtonList()
        {
            lock (GameInformation.Instance.ServerList)
            {
                foreach (GameServerInformation si in GameInformation.Instance.ServerList)
                {
                    int h = serverButtonList.Count / 2;
                    int w = serverButtonList.Count % 2 == 0 ? -1 : 1;

                    Vector2 buttonCenter = new Vector2(175 * w, 87 * h - 230);

                    serverButtonList.Add(
                        new ServerButton(si, buttonCenter,
                                         (sender) =>
                    {
                        serverButtonList.ForEach((x) => x.Disable());
                        GameInformation.Instance.ConnectedServerInformation = si;
                        ServerInformationHandler.ConnectToGameServer(si);
                    }));
                }

                GameInformation.Instance.ServerList.Clear();
            }
        }
Beispiel #16
0
        public void SendRequestToServer()
        {
            if (!IsPlayable)
            {
                return;
            }

            #region Left-Right sync logic
            Vector2 syncPosition = Position;

            if (InputHandler.IsBeingPressed(Keys.Left))
            {
                ForceSynchronize = true;
                SyncMobile.AddSynchronizableAction(SynchronizableAction.LeftMovement);

                if (!Movement.IsAbleToMove && IsAbleToShoot)
                {
                    SyncMobile.AddSynchronizableAction(SynchronizableAction.UnableToMove);
                }
                else
                {
                    syncPosition = SyncPosition;
                }
            }
            else if (InputHandler.IsBeingHeldDown(Keys.Left))
            {
                if (!Movement.IsAbleToMove)
                {
                    SyncMobile.AddSynchronizableAction(SynchronizableAction.UnableToMove);
                }
            }
            else if (InputHandler.IsBeingReleased(Keys.Left))
            {
                ForceSynchronize = true;
                SyncMobile.RemoveSynchronizableAction(SynchronizableAction.LeftMovement);
                SyncMobile.RemoveSynchronizableAction(SynchronizableAction.UnableToMove);
            }
            else if (InputHandler.IsBeingPressed(Keys.Right))
            {
                ForceSynchronize = true;
                SyncMobile.AddSynchronizableAction(SynchronizableAction.RightMovement);

                if (!Movement.IsAbleToMove && IsAbleToShoot)
                {
                    SyncMobile.AddSynchronizableAction(SynchronizableAction.UnableToMove);
                }
                else
                {
                    syncPosition = SyncPosition;
                }
            }
            else if (InputHandler.IsBeingHeldDown(Keys.Right))
            {
                if (!Movement.IsAbleToMove)
                {
                    SyncMobile.AddSynchronizableAction(SynchronizableAction.UnableToMove);
                }
            }
            else if (InputHandler.IsBeingReleased(Keys.Right))
            {
                ForceSynchronize = true;
                SyncMobile.RemoveSynchronizableAction(SynchronizableAction.RightMovement);
                SyncMobile.RemoveSynchronizableAction(SynchronizableAction.UnableToMove);
            }
            #endregion

            #region Up-down sync logic
            if (InputHandler.IsBeingReleased(Keys.Up) || InputHandler.IsBeingReleased(Keys.Down))
            {
                ForceSynchronize = true;
            }
            SyncPosition = syncPosition;
            #endregion

            #region Spacebar sync logic
            if (InputHandler.IsBeingPressed(Keys.Space) && IsAbleToShoot)
            {
                ForceSynchronize = true;
                SyncMobile.AddSynchronizableAction(SynchronizableAction.ChargingShot);
            }
            else if ((InputHandler.IsBeingReleased(Keys.Space) || LevelScene.HUD.StrenghtBar.IsFull) && IsAbleToShoot)
            {
                ForceSynchronize = true;
                SyncMobile.RemoveSynchronizableAction(SynchronizableAction.ChargingShot);
            }
            #endregion

            if (ForceSynchronize)
            {
                ForceSynchronize = false;
                UpdateSyncMobileToServer();

#if !DEBUGSCENE
                ServerInformationHandler.SynchronizeMobileStatus(SyncMobile);
#endif
            }
        }
Beispiel #17
0
 public void OnSendMessage(PlayerMessage message)
 {
     ServerInformationHandler.SendGameListMessage(message);
 }
Beispiel #18
0
 private void ExitDoorAction(object sender)
 {
     exitDoor.Disable();
     ServerInformationHandler.LeaveRoom();
 }
Beispiel #19
0
 private void ReadyAction(object sender)
 {
     ready.Disable();
     ServerInformationHandler.ReadyRoom();
 }
Beispiel #20
0
 private void SelectMobileAction(MobileType mobileType)
 {
     ServerInformationHandler.ChangePrimaryMobile(mobileType);
 }
Beispiel #21
0
 private void ChangeMapRightAction(object sender)
 {
     ServerInformationHandler.ChangeMap(NetworkObjectParameters.ChangeMapRight);
 }