예제 #1
0
        public bool IsCharacterNameAvailable(string name)
        {
            var cc       = new CachedCharacter();
            var criteria = new Dictionary <string, object> {
                { "name", name }
            };

            return(!(ExecuteConstructedGetStatement <CachedCharacter, ShardPreparedStatement>(ShardPreparedStatement.IsCharacterNameAvailable, criteria, cc)));
        }
예제 #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>
        /// Constructs a character cache from a list of IDisplayCharacters.
        /// </summary>
        /// <param name="characters">The list of IDisplayCharacters to construct a cache from.</param>
        /// <returns>A dictionary with the Id of each characters as the key and the cache data as the value.</returns>
        private Dictionary <int, CachedCharacter> CacheCharacters(IReadOnlyList <IDisplayCharacter> characters)
        {
            var cache = new Dictionary <int, CachedCharacter>();

            foreach (var character in characters)
            {
                int id = character.Id;
                cache[id] = new CachedCharacter()
                {
                    Position      = character.Position,
                    CurrentHealth = character.CurrentHealth,
                    MaxHealth     = character.MaxHealth
                };
            }
            return(cache);
        }