示例#1
0
        /// <summary>
        /// Updates a CombatEntity using a given template.
        /// </summary>
        /// <param name="template">The template used to update the CombatEntity.</param>
        /// <returns>Returns a read-only reference to the CombatEntity if the operation was successful. Else returns null.</returns>
        public async Task <IReadOnlyCombatEntity> UpdateAsync(CharacterTemplate template)
        {
            if (!template.EntityId.HasValue)
            {
                return(null);
            }
            CombatEntity entity;

            lock (_lock)
            {
                entity = _combatEntities.ContainsKey(template.EntityId.Value) ? _combatEntities[template.EntityId.Value] : null;
            }

            if (entity == null)
            {
                return(null);
            }

            var modified = await _combatEntityFactory.UpdateAsync(entity, template);

            if (modified == null)
            {
                return(null);
            }

            lock (_lock)
            {
                _combatEntities[modified.Id] = modified;
            }
            return(modified);
        }