Example #1
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();
        }
Example #2
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();
        }
Example #3
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;
            }
        }
        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;
            }
        }