示例#1
0
    public void CheckStatus()
    {
        float flatValue  = 0f;
        float percentage = 0f;
        bool  stun       = false;
        float gcd        = 0.5f;

        for (int i = 0; i < this.effects.Count; i++)
        {
            IEffect effect = (IEffect)this.effects [i];
            if (effect.GetType() == typeof(CrippleEffect))
            {
                CrippleEffect ce = (CrippleEffect)effect;
                flatValue  += ce.GetFlatValue();
                percentage += ce.GetPercentage();
            }
            if (effect.GetType() == typeof(StunEffect))
            {
                stun = true;
            }
        }

        this.currentSpeed = (this.speed - flatValue) * (1 - percentage);
        this.isStun       = stun;
        this.defaultGcd   = gcd;

        if (currentSpeed < 0)
        {
            this.currentSpeed = 0;
        }
    }
 public void AddEffect(IEffect effect)
 {
     if (effect != null)
     {
         if (listEffect.ContainsKey(effect.GetType())) // If effect exist
         {
             listEffect.Remove(effect.GetType());
         }
         effect.Owner = this;
         listEffect.Add(effect.GetType(), effect);
     }
 }
        public CustomEffectRunner CreateRunnerFor(IEffect effect)
        {
            CustomEffectRunner r = null;

            if (knownRunners.ContainsKey(effect.GetType()))
            {
                r        = (CustomEffectRunner)Activator.CreateInstance(knownRunners[effect.GetType()]);
                r.Effect = effect;
            }

            return(r);
        }
        public static JsonObject ToJsonObject(this IEffect effect)
        {
            Type       type   = effect.GetType();
            JsonObject result = new JsonObject();

            result.Add("Name", JsonValue.CreateStringValue(type.ToString()));

            var constructors = type.GetConstructors();
            var constructor  = constructors.Where(i => !i.GetParameters().Any(p => {
                var property = type.GetProperty(p.Name);
                if (property == null)
                {
                    return(true);
                }
                return(property.GetValue(effect) == null);
            })).FirstOrDefault(); // 取得能建構 Instance 的 Constructor

            JsonArray parameters = new JsonArray();

            var x = constructor.GetParameters();

            foreach (var param in constructor.GetParameters())
            {
                object value = type.GetProperty(param.Name).GetValue(effect);
                parameters.Add(JsonValue.CreateStringValue($"{value.GetType().ToString()}:{JsonConvert.SerializeObject(value)}"));
            }
            result.Add("Parameters", parameters);

            return(result);
        }
    public float DamageCalculation(float EM, float Thermal, float Kinetic, float Explosive)
    {
        float finalDamage    = 0;
        float EMBonus        = 0;
        float ThermalBonus   = 0;
        float KineticBonus   = 0;
        float ExplosiveBonus = 0;

        ArrayList effects = this.character.GetEffects();

        for (int i = 0; i < effects.Count; i++)
        {
            IEffect effect = (IEffect)effects [i];
            if (effect.GetType() == typeof(ResistanceBonus))
            {
                ResistanceBonus rb = (ResistanceBonus)effect;
                EMBonus        += rb.GetEM();
                ThermalBonus   += rb.GetThermal();
                KineticBonus   += rb.GetKinetic();
                ExplosiveBonus += rb.GetExplosive();
            }
        }


        finalDamage = TypeDamageCalculation(EM, this.EMResistance + EMBonus) +
                      TypeDamageCalculation(Thermal, this.ThermalResistance + ThermalBonus) +
                      TypeDamageCalculation(Kinetic, this.KineticResistance + KineticBonus) +
                      TypeDamageCalculation(Explosive, this.ExplosiveResistance + ExplosiveBonus);

        return(finalDamage);
    }
            /// <summary>
            /// Act method.
            /// </summary>
            /// <param name="value"> Value to execute behavior on. </param>
            /// <param name="cancellationToken"> Cancellation token. </param>
            public void Act(IEffect value, CancellationToken cancellationToken)
            {
                if (this.check(value))
                {
                    var behavior = this.behaviorFactory();

                    if (behavior == null)
                    {
                        throw new NullReferenceException(
                                  string.Format(
                                      "Behavior factory did not produce behavior in chain link for effect of type {0}",
                                      value.GetType()));
                    }

                    behavior.Act(value, cancellationToken);

                    if (this.firstOnly)
                    {
                        return;
                    }
                }

                if (this.nextLink == null)
                {
                    throw new InvalidOperationException(string.Format("Behavior not found for effect {0}", value));
                }

                this.nextLink.Act(value, cancellationToken);
            }
    public static bool forbiddenInContext(this IEffect effect, EffectContext context)
    {
        //if the Dictionary doesnt exist yet, build it
        if (contextForbidDict == null)
        {
            buildContextForbidDict();
        }

        //look up the effect
        Contexts C;

        if (contextForbidDict.TryGetValue(effect.GetType(), out C))
        {
            switch (context)
            {
            case EffectContext.playerCard: return(C.playerCard);

            case EffectContext.tower:      return(C.tower);

            case EffectContext.enemyCard:  return(C.enemyCard);

            case EffectContext.enemyUnit:  return(C.enemyUnit);

            default: Debug.LogWarning("Unknown Context"); return(true);
            }
        }
        else
        {
            Debug.LogError("Could not find " + effect.XMLName + " in the forbidden context dict!");
            return(true);
        }
    }
示例#8
0
        private void UpdateEffectProperties(IEffect Effect)
        {
            DataTable DT = new DataTable();

            DT.Columns.Add("Property", typeof(string));
            DT.Columns.Add("Value", typeof(string));
            if (Effect != null)
            {
                DT.Rows.Add("Name", Effect.Name);

                Type T = Effect.GetType();
                DT.Rows.Add("Type", T.Name);

                foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (PI.Name != "Name")
                    {
                        DT.Rows.Add(PI.Name, PI.GetValue(Effect, new object[] { }).ToString());
                    }
                }
            }
            TableEffectProperties.ClearSelection();
            TableEffectProperties.Columns.Clear();
            TableEffectProperties.AutoGenerateColumns = true;

            TableEffectProperties.DataSource = DT;
            TableEffectProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            TableEffectProperties.Refresh();
        }
示例#9
0
        public EffectViewModel(IEffect model)
        {
            Model       = model ?? throw new ArgumentNullException(nameof(model));
            DisplayName = NameFormatting.FormatEffectDisplayName(model.GetType().Name);

            if (Model is ICustomizableEffect customEffect)
            {
                var paramObject = customEffect.ParameterObject;
                foreach (var prop in paramObject.GetType().GetProperties())
                {
                    var value = prop.GetValue(paramObject);
                    EffectParameterViewModel paramVm;

                    if (prop.PropertyType == typeof(IEffect))
                    {
                        paramVm = new NestedEffectParameterViewModel(prop.Name, prop.PropertyType, null, value);
                    }
                    else
                    {
                        paramVm = new EffectParameterViewModel(prop.Name, prop.PropertyType, null, value);
                    }

                    paramVm.PropertyChanged += ParamVm_PropertyChanged;
                    Parameters.Add(paramVm);
                }
            }
        }
示例#10
0
 public void ApplyEffect(IEffect effect)
 {
     if (effect.GetType() == typeof(TimeEffect))
     {
         DurationEffect.Add((TimeEffect)effect);
         effect.ApplyEffect(Stats.Find(x => x.Type == effect.TargetStat));
     }
     else
     {
         effect.ApplyEffect(Stats.Find(x => x.Type == effect.TargetStat));
     }
 }
示例#11
0
    public bool HasEffect(IEffect effect)
    {
        foreach (IEffect origEffect in m_Effects)
        {
            if (origEffect.GetType() == effect.GetType())
            {
                return(true);
            }
        }

        return(false);
    }
示例#12
0
    //----------------
    // IAffectable
    //----------------
    public void AddEffect(IEffect effect)
    {
        foreach (IEffect origEffect in m_Effects)
        {
            if (origEffect.GetType() == effect.GetType())
            {
                origEffect.OnDuplicate();
                return;
            }
        }

        m_Effects.Add(effect);
    }
示例#13
0
        public void AddEffect(Type actionType, IEffect effect)
        {
            if (actionType == null)
            {
                throw new ArgumentNullException(nameof(actionType));
            }
            if (effect == null)
            {
                throw new ArgumentNullException(nameof(effect));
            }

            Type genericType = typeof(IEffect <>).MakeGenericType(actionType);

            if (!genericType.IsAssignableFrom(effect.GetType()))
            {
                throw new ArgumentException($"Effect {effect.GetType().Name} does not implement IEffect<{actionType.Name}>");
            }

            List <IEffect> effects = GetEffectsForActionType(actionType, true);

            effects.Add(effect);
        }
示例#14
0
        private static void GetActiveEffects(IEffectInput effectInput, List <Type> typesSeen)
        {
            IEffect effect = effectInput as IEffect;

            if (effect != null)
            {
                typesSeen.Add(effect.GetType());

                foreach (var input in effect.Inputs)
                {
                    GetActiveEffects(input, typesSeen);
                }
            }
        }
    public void AddEffect(IEffect effect)
    {
        var type = effect.GetType();

        if (_activeEffects.ContainsKey(type))
        {
            //reseting effect duration to max
            _activeEffects[type].LeftTime = effect.Duration;
        }
        else
        {
            var activeEffect = new ActiveEffect(effect);
            _activeEffects.Add(type, activeEffect);
            StartCoroutine(activeEffect);
        }
    }
        /// <summary>
        ///   Adds an affect.
        /// </summary>
        /// <param name="effect">The effect to add.</param>
        public virtual void AddEffect(IEffect <T> effect)
        {
            if (EffectTimes.Any(x => x.Effect == effect))
            {
                return;
            }

            if (!effect.CanBeAppliedTo(EffectTarget))
            {
                throw new WrapperException(
                          $"Failed to add effect.\r\nThe effect of type '{effect.GetType()}' can't be applied to the target of type '{EffectTarget.GetType()}'.");
            }

            effect.OnAttach(EffectTarget);
            EffectTimes.Add(new EffectTimeContainer(effect, -1));
        }
示例#17
0
        public static CoinFlipConditional CreateFromObject(IEffect source)
        {
            var type        = source.GetType();
            var conditional = new CoinFlipConditional();

            foreach (var prop in type.GetProperties())
            {
                if (prop.Name.ToLower() == "coinflip")
                {
                    conditional.FlipCoin = (bool)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "flipcoin")
                {
                    conditional.FlipCoin = (bool)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "onlyoncoinflip")
                {
                    conditional.FlipCoin = (bool)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "checktails")
                {
                    conditional.CheckTails = (bool)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "uselastcoin")
                {
                    conditional.UseLastCoin = (bool)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "coins")
                {
                    conditional.CoinsToFlip = (int)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "coinstoflip")
                {
                    conditional.CoinsToFlip = (int)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "headsforeffect")
                {
                    conditional.SuccessessForBonus = (int)prop.GetValue(source);
                }
                else if (prop.Name.ToLower() == "headsforsuccess")
                {
                    conditional.SuccessessForBonus = (int)prop.GetValue(source);
                }
            }

            return(conditional);
        }
示例#18
0
    /// <summary>
    /// returns true if the effect has [ForbidEffectDuplicates] and a duplicate of the effect is already in the effect list
    /// </summary>
    /// <param name="e"></param>
    /// <returns></returns>
    public bool additionBlockedByDuplicate(IEffect e)
    {
        foreach (System.Object attribute in e.GetType().GetCustomAttributes(true))
        {
            ForbidEffectDuplicates fed = attribute as ForbidEffectDuplicates;
            if (fed != null)
            {
                if (Effects.Any(ee => e.XMLName == ee.XMLName))
                {
                    if (Effects.Any(ee => e.strength == ee.strength))
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
示例#19
0
    public void Save(SaveData data)
    {
        string origPrefix = data.Prefix; // save original Prefix before editing it

        List <IEffect> toSave = effects.FindAll(x => x.ShouldBeSaved);

        int count = toSave.Count;

        data.Add("count", count);

        for (int i = 0; i < count; i++)
        {
            IEffect effect = toSave[i];

            data.Prefix = origPrefix + "effect_" + i + "_";

            data.Add("classType", effect.GetType().ToString());

            effect.Save(data);
        }
    }
    public void CheckStatus()
    {
        float flatValue  = 0f;
        float percentage = 0f;

        for (int i = 0; i < this.effects.Count; i++)
        {
            IEffect effect = (IEffect)this.effects [i];
            if (effect.GetType() == typeof(CrippleEffect))
            {
                CrippleEffect ce = (CrippleEffect)effect;
                flatValue  += ce.GetFlatValue();
                percentage += ce.GetPercentage();
            }
        }
        this.currentSpeed = (this.speed - flatValue) * (1 - percentage);

        if (currentSpeed < 0)
        {
            this.currentSpeed = 0;
        }

        print("Current speed is " + this.currentSpeed);
    }
示例#21
0
 public bool manages(IEffect c)
 {
     return(c.GetType() == effect.GetType());
 }
示例#22
0
        private void UpdateEffectProperties(IEffect Effect)
        {


            DataTable DT = new DataTable();
            DT.Columns.Add("Property", typeof(string));
            DT.Columns.Add("Value", typeof(string));
            if (Effect != null)
            {
                DT.Rows.Add("Name", Effect.Name);

                Type T = Effect.GetType();
                DT.Rows.Add("Type", T.Name);

                foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (PI.Name != "Name" )
                    {
                        DT.Rows.Add(PI.Name, PI.GetValue(Effect, new object[] { }).ToString());
                    }
                }
            }
            TableEffectProperties.ClearSelection();
            TableEffectProperties.Columns.Clear();
            TableEffectProperties.AutoGenerateColumns = true;

            TableEffectProperties.DataSource = DT;
            TableEffectProperties.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            TableEffectProperties.Refresh();

            

        }
示例#23
0
        private Slide CreateSlide(FileDocument document, IEffect <Slide> effect, string linkUrl)
        {
            var result = new Slide()
            {
                ImageUrl      = CreateImageUrl(document),
                ThumbnailUrl  = CreateThumbnailUrl(document),
                DocumentId    = KeyGen.NewGuid(),
                Duration      = 4000,
                BackgroundFit = Fit.Cover,
                Direction     = Direction.LeftToRight,
                Title         = GetSlideTitle(document),
                SlideLinkUrl  = linkUrl,
                LinkTarget    = LinkTarget.NewWindow,
                IsLinkEnabled = !string.IsNullOrEmpty(linkUrl)
            };

            // Add effect (if any) to the first slide
            if (effect != null)
            {
                if (effect is Parallax)
                {
                    throw new NotImplementedException();
                }
                else if (effect is KenBurnsEffect)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    throw new NotSupportedException($"Unable to persist effects of type '{effect.GetType().Name}'.");
                }
            }

            return(result);
        }
示例#24
0
 public EffectInfo(IEffect effect)
 {
     Effect      = effect;
     _effectName = Effect.GetType().Name;
 }
 public void RemoveEffect(IEffect effect)
 {
     if (effect != null)
         listEffect.Remove(effect.GetType());
 }
示例#26
0
    public void ApplyEffect(GameObject target, IEffect effect, BaseAsyncSkillEfector.EffectType type)
    {
        bool overrided = false;

        if (type == BaseAsyncSkillEfector.EffectType.Overwrite)
        {
            var effectInstance = _activeEffectList.FirstOrDefault(e => e.EffectName == effect.GetType().Name);
            var index          = _activeEffectList.IndexOf(effectInstance);
            if (index > -1)
            {
                _activeEffectList[index] = new EffectInfo(effect);
                _activeEffectList[index].Effect.Activate(target);
                overrided = true;
            }
        }

        if (!overrided)
        {
            effect.Activate(target);
            _activeEffectList.Add(new EffectInfo(effect));
        }
    }
示例#27
0
        public static void DetachEffect(this Player player, IEffect effect)
        {
            if (player == null || player.CustomProperties == null)
            {
                return;
            }

            var currentAttachedEffects = player.GetAttachedEffects();
            var targetEffect           = currentAttachedEffects.FirstOrDefault(e => e.GetType().Name == effect.GetType().Name);

            if (targetEffect != null)
            {
                currentAttachedEffects.Remove(targetEffect);
                player.SetAttachEffects(currentAttachedEffects);
            }
        }