Пример #1
0
        /// <summary>
        /// Adds the FieldMovementRateModifier to the MovementRateModifiers List. Replaces another modifier with the same ID. Sorts the new Entry: First alls additive, then all multiplicative modifiers. Calculates the new MovementRate value for the Field.
        /// </summary>
        /// <param name="movementRateModifier">The modifier to add to the list.</param>
        private void AddMovementRateModifier(Modifier.FieldMovementRateModifier movementRateModifier)
        {
            bool   ModIsInserted = false;
            double movementRate  = 1;

            for (int i = 0; i < MovementRateModifiers.Count; i++)
            {
                //Is there a modifier with the same ID? Replace it.
                if (movementRateModifier.ModifierID == MovementRateModifiers[i].ModifierID)
                {
                    MovementRateModifiers.RemoveAt(i);
                    MovementRateModifiers.Insert(i, movementRateModifier);
                    ModIsInserted = true;
                }
                //Insert the additive modifier at the end of all the additive modifiers, if there was no duplicate.
                if (!ModIsInserted && movementRateModifier.Additive && !MovementRateModifiers[i].Additive)
                {
                    MovementRateModifiers.Insert(i, movementRateModifier);
                    ModIsInserted = true;
                }
                //Insert the modifier, when the end of the list is reached and it wasn't inserted already.
                if (!ModIsInserted && i == MovementRateModifiers.Count - 1)
                {
                    MovementRateModifiers.Add(movementRateModifier);
                    ModIsInserted = true;
                }

                //If the modifier at position i is Additive, add it. If it is a multiplicator, multiply it.
                if (MovementRateModifiers[i].Additive)
                {
                    movementRate += MovementRateModifiers[i].Value;
                }
                else
                {
                    movementRate *= MovementRateModifiers[i].Value;
                }
            }

            MovementRate = movementRate;
        }
Пример #2
0
 /// <summary>
 /// Adds a MovementRateModifier to the MovementModifiers List by ID.
 /// </summary>
 /// <param name="modifierID"></param>
 /// <param name="value"></param>
 public void AddMovementRateModifier(int modifierID, double value = 1)
 {
     Modifier.FieldMovementRateModifier movementRateModifier = new Modifier.FieldMovementRateModifier(this, modifierID, value);
     AddMovementRateModifier(movementRateModifier);
 }