예제 #1
0
        /// <summary>
        /// Removes a status effect from a creature.
        /// </summary>
        /// <param name="creature">The creature to remove the status effect from.</param>
        /// <param name="statusEffectType">The type of status effect to remove.</param>
        public static void Remove(uint creature, StatusEffectType statusEffectType)
        {
            if (!HasStatusEffect(creature, statusEffectType, true))
            {
                return;
            }
            _creaturesWithStatusEffects[creature].Remove(statusEffectType);

            var statusEffectDetail = _statusEffects[statusEffectType];

            statusEffectDetail.RemoveAction?.Invoke(creature);

            if (statusEffectDetail.EffectIconId > 0)
            {
                Object.RemoveIconEffect(creature, statusEffectDetail.EffectIconId);
            }

            Messaging.SendMessageNearbyToPlayers(creature, $"{GetName(creature)}'s {statusEffectDetail.Name} effect has worn off.");
        }
예제 #2
0
        /// <summary>
        /// Gives a status effect to a creature.
        /// If creature already has the status effect, and their timer is shorter than length,
        /// it will be extended to the length specified.
        /// </summary>
        /// <param name="source">The source of the status effect.</param>
        /// <param name="creature">The creature receiving the status effect.</param>
        /// <param name="statusEffectType">The type of status effect to give.</param>
        /// <param name="length">The amount of time the status effect should last.</param>
        public static void Apply(uint source, uint creature, StatusEffectType statusEffectType, float length)
        {
            if (!_creaturesWithStatusEffects.ContainsKey(creature))
            {
                _creaturesWithStatusEffects[creature] = new Dictionary <StatusEffectType, StatusEffectGroup>();
            }

            if (!_creaturesWithStatusEffects[creature].ContainsKey(statusEffectType))
            {
                _creaturesWithStatusEffects[creature][statusEffectType] = new StatusEffectGroup();
            }

            var expiration = DateTime.UtcNow.AddSeconds(length);

            // If the existing status effect will expire later than this, exit early.
            if (_creaturesWithStatusEffects[creature].ContainsKey(statusEffectType))
            {
                if (_creaturesWithStatusEffects[creature][statusEffectType].Expiration > expiration)
                {
                    return;
                }
            }

            // Set the group details.
            _creaturesWithStatusEffects[creature][statusEffectType].Source     = source;
            _creaturesWithStatusEffects[creature][statusEffectType].Expiration = expiration;

            // Run the Grant Action, if applicable.
            var statusEffectDetail = _statusEffects[statusEffectType];

            statusEffectDetail.GrantAction?.Invoke(creature, length);

            // Add the status effect icon if there is one.
            if (statusEffectDetail.EffectIconId > 0)
            {
                Object.AddIconEffect(creature, statusEffectDetail.EffectIconId);
            }

            Messaging.SendMessageNearbyToPlayers(creature, $"{GetName(creature)} receives the effect of {statusEffectDetail.Name}.");
        }