Exemple #1
0
        public static void Start()
        {
            //Load Graphics
            Graphics.InitGraphics();

            //Load Sounds
            Audio.Init();
            Audio.PlayMusic(ClientConfiguration.Instance.MenuMusic, 3, 3, true);

            //Init Network
            Networking.Network.InitNetwork();
            Fade.FadeIn();

            //Make Json.Net Familiar with Our Object Types
            var id = Guid.NewGuid();

            foreach (var val in Enum.GetValues(typeof(GameObjectType)))
            {
                var type = ((GameObjectType)val);
                if (type != GameObjectType.Event && type != GameObjectType.Time)
                {
                    var lookup = type.GetLookup();
                    var item   = lookup.AddNew(type.GetObjectType(), id);
                    item.Load(item.JsonData);
                    lookup.Delete(item);
                }
            }
        }
Exemple #2
0
        private static void ProcessIntro()
        {
            if (ClientConfiguration.Instance.IntroImages.Count > 0)
            {
                GameTexture imageTex = Globals.ContentManager.GetTexture(
                    GameContentManager.TextureType.Image, ClientConfiguration.Instance.IntroImages[Globals.IntroIndex]
                    );

                if (imageTex != null)
                {
                    if (Globals.IntroStartTime == -1)
                    {
                        if (Fade.DoneFading())
                        {
                            if (Globals.IntroComing)
                            {
                                Globals.IntroStartTime = Globals.System.GetTimeMs();
                            }
                            else
                            {
                                Globals.IntroIndex++;
                                Fade.FadeIn();
                                Globals.IntroComing = true;
                            }
                        }
                    }
                    else
                    {
                        if (Globals.System.GetTimeMs() > Globals.IntroStartTime + Globals.IntroDelay)
                        {
                            //If we have shown an image long enough, fade to black -- keep track that the image is going
                            Fade.FadeOut();
                            Globals.IntroStartTime = -1;
                            Globals.IntroComing    = false;
                        }
                    }
                }
                else
                {
                    Globals.IntroIndex++;
                }

                if (Globals.IntroIndex >= ClientConfiguration.Instance.IntroImages.Count)
                {
                    Globals.GameState = GameStates.Menu;
                }
            }
            else
            {
                Globals.GameState = GameStates.Menu;
            }
        }
Exemple #3
0
        private static void ProcessLoading()
        {
            if (Globals.Me == null || Globals.Me.MapInstance == null)
            {
                return;
            }

            if (!_loadedTilesets && Globals.HasGameData)
            {
                Globals.ContentManager.LoadTilesets(TilesetBase.GetNameList());
                _loadedTilesets = true;
            }

            Audio.PlayMusic(MapInstance.Get(Globals.Me.CurrentMap).Music, 3, 3, true);
            Globals.GameState = GameStates.InGame;
            Fade.FadeIn();
        }
Exemple #4
0
        public static void Logout(bool characterSelect)
        {
            Audio.PlayMusic(ClientConfiguration.Instance.MenuMusic, 3, 3, true);
            Fade.FadeOut();
            PacketSender.SendLogout(characterSelect);
            Globals.LoggedIn           = false;
            Globals.WaitingOnServer    = false;
            Globals.GameState          = GameStates.Menu;
            Globals.JoiningGame        = false;
            Globals.NeedsMaps          = true;
            Globals.Picture            = null;
            Interface.Interface.HideUi = false;

            //Dump Game Objects
            Globals.Me          = null;
            Globals.HasGameData = false;
            foreach (var map in MapInstance.Lookup)
            {
                var mp = (MapInstance)map.Value;
                mp.Dispose(false, true);
            }

            foreach (var en in Globals.Entities.ToArray())
            {
                en.Value.Dispose();
            }

            MapBase.Lookup.Clear();
            MapInstance.Lookup.Clear();

            Globals.Entities.Clear();
            Globals.MapGrid = null;
            Globals.GridMaps.Clear();
            Globals.EventDialogs.Clear();
            Globals.EventHolds.Clear();
            Globals.PendingEvents.Clear();

            Interface.Interface.InitGwen();
            Fade.FadeIn();
        }
Exemple #5
0
        public static void OnKeyPressed(Keys key)
        {
            if (key == Keys.None)
            {
                return;
            }

            var consumeKey = false;

            KeyDown?.Invoke(key);
            switch (key)
            {
            case Keys.Escape:
                if (Globals.GameState != GameStates.Intro)
                {
                    break;
                }

                Fade.FadeIn();
                Globals.GameState = GameStates.Menu;

                return;
            }

            if (Controls.Controls.ControlHasKey(Control.OpenMenu, key))
            {
                if (Globals.GameState != GameStates.InGame)
                {
                    return;
                }

                Interface.Interface.GameUi?.EscapeMenu?.ToggleHidden();
            }

            if (Interface.Interface.HasInputFocus())
            {
                return;
            }

            Controls.Controls.GetControlsFor(key)
            ?.ForEach(
                control =>
            {
                if (consumeKey)
                {
                    return;
                }

                switch (control)
                {
                case Control.Screenshot:
                    Graphics.Renderer?.RequestScreenshot();

                    break;

                case Control.ToggleGui:
                    if (Globals.GameState == GameStates.InGame)
                    {
                        Interface.Interface.HideUi = !Interface.Interface.HideUi;
                    }

                    break;
                }

                switch (Globals.GameState)
                {
                case GameStates.Intro:
                    break;

                case GameStates.Menu:
                    break;

                case GameStates.InGame:
                    switch (control)
                    {
                    case Control.MoveUp:
                        break;

                    case Control.MoveLeft:
                        break;

                    case Control.MoveDown:
                        break;

                    case Control.MoveRight:
                        break;

                    case Control.AttackInteract:
                        break;

                    case Control.Block:
                        Globals.Me?.TryBlock();

                        break;

                    case Control.AutoTarget:
                        Globals.Me?.AutoTarget();

                        break;

                    case Control.PickUp:
                        Globals.Me?.TryPickupItem();

                        break;

                    case Control.Enter:
                        Interface.Interface.GameUi.FocusChat = true;
                        consumeKey = true;

                        return;

                    case Control.Hotkey1:
                    case Control.Hotkey2:
                    case Control.Hotkey3:
                    case Control.Hotkey4:
                    case Control.Hotkey5:
                    case Control.Hotkey6:
                    case Control.Hotkey7:
                    case Control.Hotkey8:
                    case Control.Hotkey9:
                    case Control.Hotkey0:
                        var index = control - Control.Hotkey1;
                        if (0 <= index && index < Interface.Interface.GameUi?.Hotbar?.Items?.Count)
                        {
                            Interface.Interface.GameUi?.Hotbar?.Items?[index]?.Activate();
                        }
                        else
                        {
                            Log.Warn(
                                Interface.Interface.GameUi?.Hotbar?.Items == null
                                                    ? $"Tried to press Hotkey{(index + 1) % 10} but the hotbar items are null."
                                                    : $"Tried to press Hotkey{(index + 1) % 10} which was out of bounds ({control})."
                                );
                        }

                        break;

                    case Control.OpenInventory:
                        Interface.Interface.GameUi?.GameMenu?.ToggleInventoryWindow();

                        break;

                    case Control.OpenQuests:
                        Interface.Interface.GameUi?.GameMenu?.ToggleQuestsWindow();

                        break;

                    case Control.OpenCharacterInfo:
                        Interface.Interface.GameUi?.GameMenu?.ToggleCharacterWindow();

                        break;

                    case Control.OpenParties:
                        Interface.Interface.GameUi?.GameMenu?.TogglePartyWindow();

                        break;

                    case Control.OpenSpells:
                        Interface.Interface.GameUi?.GameMenu?.ToggleSpellsWindow();

                        break;

                    case Control.OpenFriends:
                        Interface.Interface.GameUi?.GameMenu?.ToggleFriendsWindow();

                        break;

                    case Control.OpenSettings:
                        Interface.Interface.GameUi?.EscapeMenu?.OpenSettings();

                        break;

                    case Control.OpenDebugger:
                        Interface.Interface.GameUi?.ShowHideDebug();

                        break;

                    case Control.OpenAdminPanel:
                        PacketSender.SendOpenAdminWindow();

                        break;
                    }

                    break;

                case GameStates.Loading:
                    break;

                case GameStates.Error:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        nameof(Globals.GameState), Globals.GameState, null
                        );
                }
            }
                );
        }
Exemple #6
0
        public static void OnKeyPressed(Keys key)
        {
            if (key == Keys.None)
            {
                return;
            }

            var  consumeKey   = false;
            bool canFocusChat = true;

            KeyDown?.Invoke(key);
            switch (key)
            {
            case Keys.Escape:
                if (Globals.GameState != GameStates.Intro)
                {
                    break;
                }

                Fade.FadeIn();
                Globals.GameState = GameStates.Menu;

                return;

            case Keys.Enter:

                for (int i = Interface.Interface.InputBlockingElements.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var iBox = (InputBox)Interface.Interface.InputBlockingElements[i];
                        if (iBox != null && !iBox.IsHidden)
                        {
                            iBox.okayBtn_Clicked(null, null);
                            canFocusChat = false;

                            break;
                        }
                    }
                    catch { }

                    try
                    {
                        var eventWindow = (EventWindow)Interface.Interface.InputBlockingElements[i];
                        if (eventWindow != null && !eventWindow.IsHidden && Globals.EventDialogs.Count > 0)
                        {
                            eventWindow.EventResponse1_Clicked(null, null);
                            canFocusChat = false;

                            break;
                        }
                    }
                    catch { }
                }

                break;
            }

            if (Controls.Controls.ControlHasKey(Control.OpenMenu, key))
            {
                if (Globals.GameState != GameStates.InGame)
                {
                    return;
                }

                // First try and unfocus chat then close all UI elements, then untarget our target.. and THEN open the escape menu.
                // Most games do this, why not this?
                if (Interface.Interface.GameUi != null && Interface.Interface.GameUi.ChatFocussed)
                {
                    Interface.Interface.GameUi.UnfocusChat = true;
                }
                else if (Interface.Interface.GameUi != null && Interface.Interface.GameUi.CloseAllWindows())
                {
                    // We've closed our windows, don't do anything else. :)
                }
                else if (Globals.Me != null && Globals.Me.TargetIndex != Guid.Empty)
                {
                    Globals.Me.ClearTarget();
                }
                else
                {
                    Interface.Interface.GameUi?.EscapeMenu?.ToggleHidden();
                }
            }

            if (Interface.Interface.HasInputFocus())
            {
                return;
            }

            Controls.Controls.GetControlsFor(key)
            ?.ForEach(
                control =>
            {
                if (consumeKey)
                {
                    return;
                }

                switch (control)
                {
                case Control.Screenshot:
                    Graphics.Renderer?.RequestScreenshot();

                    break;

                case Control.ToggleGui:
                    if (Globals.GameState == GameStates.InGame)
                    {
                        Interface.Interface.HideUi = !Interface.Interface.HideUi;
                    }

                    break;
                }

                switch (Globals.GameState)
                {
                case GameStates.Intro:
                    break;

                case GameStates.Menu:
                    break;

                case GameStates.InGame:
                    switch (control)
                    {
                    case Control.MoveUp:
                        break;

                    case Control.MoveLeft:
                        break;

                    case Control.MoveDown:
                        break;

                    case Control.MoveRight:
                        break;

                    case Control.AttackInteract:
                        break;

                    case Control.Block:
                        Globals.Me?.TryBlock();

                        break;

                    case Control.AutoTarget:
                        Globals.Me?.AutoTarget();

                        break;

                    case Control.PickUp:
                        Globals.Me?.TryPickupItem(Globals.Me.MapInstance.Id, Globals.Me.Y * Options.MapWidth + Globals.Me.X);

                        break;

                    case Control.Enter:
                        if (canFocusChat)
                        {
                            Interface.Interface.GameUi.FocusChat = true;
                            consumeKey = true;
                        }

                        return;

                    case Control.Hotkey1:
                    case Control.Hotkey2:
                    case Control.Hotkey3:
                    case Control.Hotkey4:
                    case Control.Hotkey5:
                    case Control.Hotkey6:
                    case Control.Hotkey7:
                    case Control.Hotkey8:
                    case Control.Hotkey9:
                    case Control.Hotkey0:
                        break;

                    case Control.OpenInventory:
                        Interface.Interface.GameUi?.GameMenu?.ToggleInventoryWindow();

                        break;

                    case Control.OpenQuests:
                        Interface.Interface.GameUi?.GameMenu?.ToggleQuestsWindow();

                        break;

                    case Control.OpenCharacterInfo:
                        Interface.Interface.GameUi?.GameMenu?.ToggleCharacterWindow();

                        break;

                    case Control.OpenParties:
                        Interface.Interface.GameUi?.GameMenu?.TogglePartyWindow();

                        break;

                    case Control.OpenSpells:
                        Interface.Interface.GameUi?.GameMenu?.ToggleSpellsWindow();

                        break;

                    case Control.OpenFriends:
                        Interface.Interface.GameUi?.GameMenu?.ToggleFriendsWindow();

                        break;

                    case Control.OpenSettings:
                        Interface.Interface.GameUi?.EscapeMenu?.OpenSettings();

                        break;

                    case Control.OpenDebugger:
                        Interface.Interface.GameUi?.ShowHideDebug();

                        break;

                    case Control.OpenAdminPanel:
                        PacketSender.SendOpenAdminWindow();

                        break;

                    case Control.OpenGuild:
                        Interface.Interface.GameUi?.GameMenu.ToggleGuildWindow();

                        break;
                    }

                    break;

                case GameStates.Loading:
                    break;

                case GameStates.Error:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        nameof(Globals.GameState), Globals.GameState, null
                        );
                }
            }
                );
        }