public static double SharedGetStatusEffectIntensity(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect)
        {
            if (protoStatusEffect is null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            var statusEffects = InternalSharedGetStatusEffects(character);

            foreach (var statusEffect in statusEffects)
            {
                if (statusEffect.ProtoGameObject != protoStatusEffect)
                {
                    continue;
                }

                if (Api.IsClient &&
                    statusEffect.IsDestroyed)
                {
                    // the status effect might be already destroyed but its intensity could be > 0
                    return(0);
                }

                // found effect to set intensity
                var state = statusEffect.GetPublicState <StatusEffectPublicState>();
                return(state.Intensity);
            }

            // status effect not found - intensity 0
            return(0);
        }
        public static void ServerRemoveStatusEffectIntensity(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect,
            double intensityToRemove)
        {
            if (protoStatusEffect is null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            if (intensityToRemove <= 0)
            {
                throw new ArgumentException("Intensity to remove must be > 0", nameof(intensityToRemove));
            }

            var statusEffects = InternalServerGetStatusEffects(character);

            foreach (var statusEffect in statusEffects)
            {
                if (statusEffect.ProtoGameObject != protoStatusEffect)
                {
                    continue;
                }

                // found effect to reduce intensity
                var state = statusEffect.GetPublicState <StatusEffectPublicState>();
                state.SetIntensity(state.Intensity - intensityToRemove);
                return;
            }
        }
        public static void ServerSetStatusEffectIntensity(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect,
            double intensity)
        {
            if (protoStatusEffect is null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            var statusEffects = InternalServerGetStatusEffects(character);

            foreach (var statusEffect in statusEffects)
            {
                if (statusEffect.ProtoGameObject != protoStatusEffect)
                {
                    continue;
                }

                // found effect to set intensity
                var state = statusEffect.GetPublicState <StatusEffectPublicState>();
                state.SetIntensity(intensity);
                return;
            }

            // status effect instance is not found
            if (intensity > 0)
            {
                ServerAddStatusEffect(character, protoStatusEffect, intensity);
            }
        }
        public static void ServerRemoveStatusEffect(
            this ICharacter character,
            IProtoStatusEffect protoStatusEffect)
        {
            if (protoStatusEffect is null)
            {
                throw new ArgumentNullException(nameof(protoStatusEffect));
            }

            var statusEffects = InternalServerGetStatusEffects(character);

            for (var index = 0; index < statusEffects.Count; index++)
            {
                var statusEffect = statusEffects[index];
                if (statusEffect.ProtoGameObject != protoStatusEffect)
                {
                    continue;
                }

                // found effect to remove
                statusEffects.RemoveAt(index);
                ServerWorld.DestroyObject(statusEffect);
                Logger.Info($"Status effect removed: {statusEffect} from {character}");
                return;
            }

            // no status effect found
            Logger.Warning($"Cannot remove status effect: {protoStatusEffect} from {character}");
        }
예제 #5
0
 public string Execute(
     IProtoStatusEffect statusEffect,
     double intensityToAdd = 1.0,
     [CurrentCharacterIfNull] ICharacter player = null)
 {
     player.ServerAddStatusEffect(statusEffect, intensityToAdd);
     return(null);
 }
예제 #6
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);
        }
예제 #7
0
 public EffectAction(
     IProtoStatusEffect protoStatusEffect,
     double intensity,
     [CanBeNull] DelegeteEffectActionCondition condition = null,
     bool isHidden = false)
 {
     this.Condition         = condition;
     this.IsHidden          = isHidden;
     this.ProtoStatusEffect = protoStatusEffect;
     Api.Assert(intensity != 0, "Intensity cannot be 0");
     this.Intensity = MathHelper.Clamp(intensity, -1, 1);
 }
예제 #8
0
        public ViewModelStatusEffect(ILogicObject statusEffect)
        {
            this.statusEffect      = statusEffect;
            this.protoStatusEffect = (IProtoStatusEffect)statusEffect.ProtoLogicObject;

            this.publicState = statusEffect.GetPublicState <StatusEffectPublicState>();
            this.publicState.ClientSubscribe(
                _ => _.Intensity,
                _ => this.UpdateIntensity(),
                this);

            this.UpdateIntensity();
        }
예제 #9
0
        public ViewModelStatusEffect(ILogicObject statusEffect)
        {
            this.statusEffect      = statusEffect;
            this.protoStatusEffect = (IProtoStatusEffect)statusEffect.ProtoLogicObject;
            this.lazyEffects       = new Lazy <IReadOnlyList <StatModificationData> >(this.CreateEffectsList);

            this.publicState = statusEffect.GetPublicState <StatusEffectPublicState>();
            this.publicState.ClientSubscribe(
                _ => _.Intensity,
                _ => this.UpdateIntensity(),
                this);

            this.UpdateIntensity();
        }
예제 #10
0
        protected override void PrepareProtoStatusEffect()
        {
            instance = this;

            if (IsServer)
            {
                // setup timer (tick every frame)
                TriggerEveryFrame.ServerRegister(
                    callback: ServerGlobalUpdate,
                    name: "System." + this.ShortId);

                PlayerCharacterTechnologies.ServerCharacterGainedLearningPoints +=
                    this.ServerPlayerCharacterGainedLearningPointsHandler;
            }
        }
예제 #11
0
        protected override void PrepareProtoStatusEffect()
        {
            instance = this;

            if (IsServer)
            {
                if (!SharedLocalServerHelper.IsLocalServer)
                {
                    TriggerEveryFrame.ServerRegister(
                        callback: ServerGlobalUpdate,
                        name: "System." + this.ShortId);
                }

                PlayerCharacterTechnologies.ServerCharacterGainedLearningPoints
                    += this.ServerPlayerCharacterGainedLearningPointsHandler;
            }
        }
예제 #12
0
        public ViewModelStatusEffect(ILogicObject statusEffect)
        {
            this.protoStatusEffect = (IProtoStatusEffect)statusEffect.ProtoLogicObject;
            this.StatsDictionary   = this.protoStatusEffect.ProtoEffects;

            this.publicState = statusEffect.GetPublicState <StatusEffectPublicState>();
            this.publicState.ClientSubscribe(
                _ => _.Intensity,
                _ => this.UpdateIntensity(),
                this);

            this.UpdateIntensity();

            this.IsFlickerScheduled = true;

            var controls = new List <UIElement>();

            this.PopulateControls(controls);

            if (controls.Count > 0)
            {
                this.InfoControls = controls;
            }
        }
예제 #13
0
 public ProtoStatusEffectViewModel([NotNull] IProtoStatusEffect statusEffect)
     : base(statusEffect)
 {
     Description = statusEffect.Description;
     Kind        = statusEffect.Kind;
 }
        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;
            }
        }
예제 #15
0
 public ViewModelPublicStatusEffect(IProtoStatusEffect protoStatsEffect)
 {
     this.protoStatusEffect = protoStatsEffect;
 }
 public string Execute(IProtoStatusEffect statusEffect, [CurrentCharacterIfNull] ICharacter player)
 {
     player.ServerRemoveStatusEffect(statusEffect);
     return(null);
 }