Ejemplo n.º 1
0
        public void AddItemAsCraftingIngredient()
        {
            int item = Util.GetCurrentItem();

            if (item == 0)
            {
                UISystem.Message("Your inventory is empty!");
                return;
            }
            AddItemAsIngredientEvent?.Invoke(item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (Util.ErrorOccured)
            {
                if (!Util.BrutalModeOn)
                {
                    UISystem.Message("A CRITICAL ERROR HAS OCCURED!");
                    Exit();
                }
            }

            if (gameOver)
            {
                if (InputManager.Instance.CheckKey(Keys.Escape))
                {
                    Exit();
                }

                // ignore all other input
                base.Update(gameTime);
                return;
            }

            // check for input
            if (InputManager.Instance.CheckInput(gameTime))
            {
                InputManager.Instance.ExecuteCurrentCommand();

                if (Util.PlayerTurnOver)
                {
                    npcBehaviourSystem.EnemyTurn();
                    Util.PlayerTurnOver = false;
                }

                float playerHealth = EntityManager.GetComponent <HealthComponent>(Util.PlayerID).Amount;
                if (playerHealth <= 0)
                {
                    UISystem.Message("---");
                    UISystem.Message("You died.");
                    UISystem.Message("");
                    UISystem.Message("Press ESC to exit...");

                    gameOver = true;
                }

                // remove all entities that died this turn
                EntityManager.CleanUpEntities();
            }

            base.Update(gameTime);
        }
Ejemplo n.º 3
0
        public void LoadKeyBindings(string Json)
        {
            keyToCommand = Util.DeserializeObject <Dictionary <CommandDomain, Dictionary <Keys, Command> > >(Json);

            if (keyToCommand == null)
            {
                Log.Error("Failed to load keybindings!");
                UISystem.Message("Failed to load keybindings!");
                keyToCommand = new Dictionary <CommandDomain, Dictionary <Keys, Command> >()
                {
                    { CommandDomain.Exploring, new Dictionary <Keys, Command>() }
                };
            }
        }
Ejemplo n.º 4
0
        private void ConsumeItem()
        {
            var item = Util.GetCurrentItem();

            if (item == 0)
            {
                return;
            }

            var consumable = EntityManager.GetComponent <ConsumableComponent>(item);

            if (consumable == null)
            {
                UISystem.Message("I can't consume that!");
                return;
            }

            ItemConsumedEvent?.Invoke(ControlledEntity, item);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// checks if item is usable
        /// prints problems to player if any
        /// </summary>
        /// <returns> wether item is usable </returns>
        private bool ItemUsable(int item, ItemUsage usage)
        {
            if (item == 0)
            {
                UISystem.Message("Your inventory is empty!");
                return(false);
            }

            var usableItem = EntityManager.GetComponent <UsableItemComponent>(item);

            if (usableItem == null)
            {
                UISystem.Message("You can't use that!");
                return(false);
            }

            if (!usableItem.Usages.Contains(usage))
            {
                UISystem.Message("Item usage:");
                foreach (var action in usableItem.Usages)
                {
                    Keys key = Keys.None;
                    switch (action)
                    {
                    case ItemUsage.Consume:
                        key = GetKeybinding(Command.ConsumeItem, CommandDomain.Inventory);
                        break;

                    case ItemUsage.Throw:
                        key = GetKeybinding(Command.ThrowItem, CommandDomain.Inventory);
                        break;
                    }
                    UISystem.Message(key + " -> " + action);
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks for user input and executes corresponding command if input is present
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>wether input/command is available</returns>
        public bool CheckInput(GameTime gameTime)
        {
            KeyboardState curKeyState = Keyboard.GetState();

            if (curKeyState == prevKeyState)
            {
                if (curKeyState == noKeyPressed)
                {
                    return(false);
                }

                keyHeldDownFor += gameTime.ElapsedGameTime.Milliseconds;

                if (keyHeldDownFor < keyHoldDelay)
                {
                    return(false);
                }
                else
                {
                    keyHeldDownFor = keyHoldDelay - heldDownInputDelay;
                }
            }
            else
            {
                prevKeyState   = curKeyState;
                keyHeldDownFor = 0;

                shift = curKeyState.IsKeyDown(Keys.LeftShift) || curKeyState.IsKeyDown(Keys.RightShift);
                ctrl  = curKeyState.IsKeyDown(Keys.LeftControl) || curKeyState.IsKeyDown(Keys.RightControl);
                alt   = curKeyState.IsKeyDown(Keys.LeftAlt);

                //Console.WriteLine("Mods (shift|ctrl|alt): " + shift + "|" + ctrl + "|" + alt);
            }

            if (curKeyState == noKeyPressed)
            {
                return(false);
            }

            CommandDomain curDomain = domainHistory.Peek();

            if (!keyToCommand.ContainsKey(curDomain))
            {
                Log.Error("Command domain not present: " + curDomain);
                return(false);
            }

            var keyBindings = keyToCommand[curDomain];

            if (keyBindings == null)
            {
                Log.Error("Key bindings missing for " + curDomain);
                return(false);
            }

            Command command = Command.None;

            //StringBuilder sb = new StringBuilder();

            //foreach (var keyPressed in curKeyState.GetPressedKeys())
            //{
            //    sb.AppendFormat("{0}, ", keyPressed);
            //}

            //Log.Message(sb.ToString());

            foreach (var keyPressed in curKeyState.GetPressedKeys())
            {
                if (keyPressed == Keys.F1)
                {
                    EntityManager.Dump();
                    continue;
                }

                // TODO: implement modifiers
                if (keyBindings.ContainsKey(keyPressed))
                {
                    command = keyBindings[keyPressed];
                    break;
                }
            }



            if (command == Command.None)
            {
                UISystem.Message("Unkown Command!");
                return(false);
            }

            //ExecuteCommand(command);
            curCommand = command;
            return(true);
        }