예제 #1
0
 /// <summary>
 /// Checks to see if movement upward in the formation panel should be blocked based on the current position of the
 /// player's target.
 /// </summary>
 /// <returns>Returns true if movement should be blocked.</returns>
 private bool IsUpArrowBlocked()
 {
     if (_defaultsHandler.ActiveAction.CanTargetThroughUnits)
     {
         return(false);
     }
     if (!_defaultsHandler.ActiveAction.CanSwitchTargetPosition)
     {
         return(true);
     }
     // Action can only be blocked when not on the player's side of the field and not in the enemy's first column
     if (_defaultsHandler.CurrentTargetPosition % 3 != 1 && _defaultsHandler.CurrentTargetPosition >= 10)
     {
         // If the target position is in the 3rd column, check if the 1st or 2nd column of the row is occupied, if so action is blocked
         if (_defaultsHandler.CurrentTargetPosition % 3 == 0 &&
             _uiCharacterManager.CharacterInPositionExists(_defaultsHandler.CurrentTargetPosition - 5, false))
         {
             return(true);
         }
         else if (_uiCharacterManager.CharacterInPositionExists(_defaultsHandler.CurrentTargetPosition - 4, false))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
        /// <summary>
        /// Returns a details panel injected with the data from a character.
        /// </summary>
        /// <param name="character">The character whose data will be used to fill the details panel.</param>
        /// <returns>A read-only list of string that contains the details panel.</returns>
        public IReadOnlyList <string> Render()
        {
            IDisplayCharacter focusedTarget;
            IReadOnlyList <IDisplayCharacter> otherTargets = new List <IDisplayCharacter>();
            var targets = _uiStateTracker.CurrentTargetPositions;

            // If there are no characters within any of our target positions, return the current turn character
            if (!targets.Any(targetPosition =>
                             _uiCharacterManager.GetCharacterFromPosition(targetPosition) != null))
            {
                focusedTarget = _uiCharacterManager.GetCurrentTurnCharacter();
            }
            // If our main target position is occupied, display that target
            else if (_uiCharacterManager.CharacterInPositionExists(_uiStateTracker.CurrentTargetPosition) &&
                     targets.Contains(_uiStateTracker.CurrentTargetPosition))
            {
                focusedTarget = _uiCharacterManager.GetCharacterFromPosition(_uiStateTracker.CurrentTargetPosition);
                otherTargets  = _uiCharacterManager.GetCharactersFromPositions(targets);
            }
            // If our main target position isn't occupied, display any target that occupies a spot in our target list
            else
            {
                focusedTarget = _uiCharacterManager.Characters.First(
                    character => targets.Contains(character.Position));
                otherTargets = _uiCharacterManager.GetCharactersFromPositions(targets);
            }

            if (otherTargets.Count() > 0)
            {
                return(Render(otherTargets, focusedTarget));
            }

            if (focusedTarget == null)
            {
                throw new NullReferenceException();
            }
            if (IsCachedData(focusedTarget))
            {
                return(_cachedRender);
            }
            else
            {
                _cachedCharacter = new CachedCharacter()
                {
                    Id            = focusedTarget.Id,
                    CurrentHealth = focusedTarget.CurrentHealth,
                    MaxHealth     = focusedTarget.MaxHealth
                };
            }

            var characterDetails = new List <string>();

            characterDetails.AddRange(RenderCharacter(focusedTarget));

            _cachedRender = characterDetails;
            return(characterDetails);
        }
예제 #3
0
        /// <summary>
        /// Handles any actions that occurs after the enter key is pressed.
        /// </summary>
        private void EnterKeyPressed()
        {
            // If the player is in the command panel
            if (!_uiStateTracker.IsInActionPanel &&
                !_uiStateTracker.IsInFormationPanel &&
                !_uiStateTracker.IsInCategoryPanel &&
                !_uiStateTracker.IsInCharacterPanel)
            {
                switch ((Commands)_uiStateTracker.CommandFocusNumber)
                {
                case Commands.Attack:
                    _uiStateTracker.IsInActionPanel  = true;
                    _uiStateTracker.IsInCommandPanel = false;
                    UpdateActionListEvent?.Invoke(this, new UpdateActionListEventArgs()
                    {
                        CommandFocus = (Commands)_uiStateTracker.CommandFocusNumber,
                        CategoryName = _uiStateTracker.ActiveCategory
                    });
                    break;

                case Commands.Spells:
                case Commands.Skills:
                case Commands.Items:
                    if (_uiStateTracker.CategoryItemCount > 0)
                    {
                        _uiStateTracker.IsInCategoryPanel = true;
                        _uiStateTracker.IsInCommandPanel  = false;
                    }
                    break;

                case Commands.Status:
                    _uiStateTracker.IsInFormationPanel = true;
                    _uiStateTracker.IsInCommandPanel   = false;
                    _uiStateTracker.IsInStatusCommand  = true;
                    int?position = _uiCharacterManager.GetPositionOfCharacter(_uiStateTracker.ActiveCharacterId);

                    if (position == null)
                    {
                        throw new Exception("Active character was not found in UICharacterManager.");
                    }
                    else
                    {
                        _uiStateTracker.CurrentTargetPosition  = position.GetValueOrDefault();
                        _uiStateTracker.CurrentTargetPositions = new List <int>()
                        {
                            position.GetValueOrDefault()
                        };
                        _uiStateTracker.ActiveAction.CanSwitchTargetPosition = true;
                        _uiStateTracker.ActiveAction.CanTargetThroughUnits   = true;
                        _uiStateTracker.ActiveAction.CenterOfTargets         = 5;
                        _uiStateTracker.ActiveAction.TargetPositions         = new List <int>()
                        {
                            5
                        };
                        _uiStateTracker.IsInStatusCommand = true;
                    }
                    break;

                case Commands.Wait:
                    ActionStartedEvent?.Invoke(this, new ActionStartedEventArgs()
                    {
                        ActionType     = Commands.Wait,
                        CategoryName   = "",
                        ActionIndex    = -1,
                        TargetPosition = 0
                    });
                    break;
                }
            }
            // If the player is in the formation panel, start an action
            else if (_uiStateTracker.IsInFormationPanel && !_uiStateTracker.IsInStatusCommand)
            {
                var target = _uiStateTracker.CurrentTargetPosition;

                ActionStartedEvent?.Invoke(this, new ActionStartedEventArgs()
                {
                    ActionType     = (Commands)_uiStateTracker.CommandFocusNumber,
                    CategoryName   = _uiStateTracker.ActiveCategory,
                    ActionIndex    = _uiStateTracker.ActionFocusNumber - 1,
                    TargetPosition = target
                });
            }
            else if (_uiStateTracker.IsInStatusCommand && !_uiStateTracker.IsInCharacterPanel)
            {
                if (_uiCharacterManager.CharacterInPositionExists(_uiStateTracker.CurrentTargetPosition))
                {
                    _uiStateTracker.IsInCharacterPanel = true;
                    _uiStateTracker.IsInFormationPanel = false;
                }
            }
            // If the player is in the action panel, switch to the formation panel
            else if (_uiStateTracker.IsInActionPanel)
            {
                switch ((Commands)_uiStateTracker.CommandFocusNumber)
                {
                case Commands.Attack:
                case Commands.Spells:
                case Commands.Skills:
                case Commands.Items:
                    _uiStateTracker.IsInFormationPanel = true;
                    _uiStateTracker.IsInActionPanel    = false;
                    ActionSelectedEvent?.Invoke(this, new ActionSelectedEventArgs()
                    {
                        CommandFocus      = (Commands)_uiStateTracker.CommandFocusNumber,
                        CategoryName      = _uiStateTracker.ActiveCategory,
                        ActionFocusNumber = _uiStateTracker.ActionFocusNumber
                    });
                    break;

                default:
                    break;
                }
            }
            else if (_uiStateTracker.IsInCategoryPanel)
            {
                // Get all spells or skills in category
                UpdateActionListEvent?.Invoke(this, new UpdateActionListEventArgs()
                {
                    CommandFocus = (Commands)_uiStateTracker.CommandFocusNumber,
                    CategoryName = _uiStateTracker.ActiveCategory
                });

                _uiStateTracker.IsInActionPanel   = true;
                _uiStateTracker.IsInCategoryPanel = false;
            }
        }