Example #1
0
        public static void ServerAddStatusEffect(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect,
            double intensity)
        {
            if (protoStatusEffect == null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            if (intensity <= 0)
            {
                throw new ArgumentException(
                          $"Intensity to add must be > 0. Provided value: {intensity:F2}",
                          nameof(intensity));
            }

            if (character.ProtoCharacter is PlayerCharacterSpectator ||
                ServerCharacters.IsSpectator(character))
            {
                // don't add status effects to the spectator characters
                return;
            }

            if (intensity > 1)
            {
                // clamp intensity to add
                intensity = 1;
            }

            ILogicObject statusEffect = null;

            var statusEffects = InternalServerGetStatusEffects(character);

            foreach (var existingStatusEffect in statusEffects)
            {
                if (existingStatusEffect.ProtoGameObject == protoStatusEffect)
                {
                    statusEffect = existingStatusEffect;
                    break;
                }
            }

            if (statusEffect == null)
            {
                // no such status effect instance exists - create and add it
                statusEffect = ServerWorld.CreateLogicObject(protoStatusEffect);
                protoStatusEffect.ServerSetup(statusEffect, character);
                statusEffects.Add(statusEffect);
                Logger.Info($"Status effect added: {statusEffect} to {character}");
            }

            protoStatusEffect.ServerAddIntensity(statusEffect, intensity);
        }
        public static void ServerAddStatusEffect(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect,
            double intensity = 1.0)
        {
            if (protoStatusEffect is null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            if (intensity <= 0)
            {
                throw new ArgumentException(
                          $"Intensity to add must be > 0. Provided value: {intensity:F2}",
                          nameof(intensity));
            }

            if (character.ProtoCharacter is PlayerCharacterSpectator ||
                ServerCharacters.IsSpectator(character))
            {
                // don't add status effects to the spectator characters
                return;
            }

            if (intensity > 1)
            {
                // clamp intensity to add
                intensity = 1;
            }

            ILogicObject statusEffect = null;

            var statusEffects = InternalServerGetStatusEffects(character);

            foreach (var existingStatusEffect in statusEffects)
            {
                if (existingStatusEffect.ProtoGameObject == protoStatusEffect)
                {
                    statusEffect = existingStatusEffect;
                    break;
                }
            }

            if (statusEffect is null)
            {
                // no such status effect instance exists - create and add it
                statusEffect = ServerWorld.CreateLogicObject(protoStatusEffect);
                protoStatusEffect.ServerSetup(statusEffect, character);
                statusEffects.Add(statusEffect);
                Logger.Info($"Status effect added: {statusEffect} to {character}");
            }

            protoStatusEffect.ServerAddIntensity(statusEffect, intensity);

            var publicState = statusEffect.GetPublicState <StatusEffectPublicState>();

            var damageContext = CharacterDamageContext.Current;
            var byCharacter   = damageContext.AttackerCharacter;

            if (!ReferenceEquals(byCharacter, null))
            {
                publicState.ServerStatusEffectWasAddedByCharacter            = byCharacter;
                publicState.ServerStatusEffectWasAddedByCharacterWeaponSkill = damageContext.ProtoWeaponSkill;
            }
        }