Пример #1
0
        /// <summary>
        /// Returns a string describing this heal result.
        /// </summary>
        /// <param name="heal">The heal result.</param>
        public static string Describe <TSource>(this HealActionResult <TSource> heal)
        {
            var target = heal.Target;

            if (heal.IsSelfInflicted)
            {
                return(heal.Source switch
                {
                    Item item => $"{target.Name}'s {item.Name} restored {heal.Amount} health to them!",
                    _ => $"{target.Name} recovered {heal.Amount} health!",
                });
Пример #2
0
        private void Heal()
        {
            _messagesFromActions.Add("Heal");
            HealActionResult result = _game.Heal();

            if (!result.IsSeccessful)
            {
                _messagesFromActions.Add("Heal fail (no money)");
            }
            else
            {
                _messagesFromActions.Add(string.Format("Heal action for: {0}", result.HealAction));
            }
        }
Пример #3
0
        /// <summary>
        /// Restores the given amount of health, capped by the character's max health, and returns the result.
        /// </summary>
        /// <param name="amount">The healing amount.</param>
        /// <param name="user">The character who used the incoming heal.</param>
        /// <typeparam name="TSource">The type of the source of the incoming heal.</typeparam>
        public virtual HealActionResult <TSource> Heal <TSource>(
            int amount,
            Character user)
        {
            HealActionResult <TSource> result;

            if (CanProtectFrom(user))
            {
                var protectUser = ConsumeProtect();

                result = new HealActionResult <TSource>
                {
                    Applied         = false,
                    User            = user,
                    Target          = this,
                    TargetProtected = true,
                    ProtectUser     = protectUser,
                    Tags            = new HashSet <string>(),
                };
            }
            else
            {
                var startingHealth = CurrentHealth;
                CurrentHealth += Math.Min(MaxHealth - CurrentHealth, amount);
                var endingHealth = CurrentHealth;

                result = new HealActionResult <TSource>
                {
                    Applied         = true,
                    User            = user,
                    Target          = this,
                    TargetProtected = false,
                    StartingHealth  = startingHealth,
                    EndingHealth    = endingHealth,
                    Tags            = new HashSet <string>(),
                };
            }

            return(result);
        }