/// <summary> /// Calculates the modified Stat value. /// </summary> /// <typeparam name="TStatType">The type of the stat.</typeparam> /// <param name="baseStats">The collection of unmodified Stats to read the base stat value from.</param> /// <param name="statType">The <typeparamref name="TStatType"/> to calculate the value for.</param> /// <param name="modder1">The first <see cref="IModStatContainer{TStatType}"/>s to use for calculating /// the modified stat value.</param> /// <param name="modder2">The second <see cref="IModStatContainer{TStatType}"/>s to use for calculating /// the modified stat value.</param> /// <param name="modder3">The third <see cref="IModStatContainer{TStatType}"/>s to use for calculating /// the modified stat value.</param> /// <returns>The modified stat value.</returns> public static int Calculate <TStatType>(IStatCollection <TStatType> baseStats, TStatType statType, IModStatContainer <TStatType> modder1, IModStatContainer <TStatType> modder2, IModStatContainer <TStatType> modder3) where TStatType : struct, IComparable, IConvertible, IFormattable { int value = baseStats[statType]; value += modder1.GetStatModBonus(statType); value += modder2.GetStatModBonus(statType); value += modder3.GetStatModBonus(statType); return(value); }
/// <summary> /// Calculates the modified stat value. /// </summary> /// <typeparam name="TStatType">The type of the stat.</typeparam> /// <param name="baseStats">The collection of unmodified stats to read the base stat value from.</param> /// <param name="statType">The <typeparamref name="TStatType"/> to calculate the value for.</param> /// <param name="modders">The <see cref="IModStatContainer{TStatType}"/>s to use for calculating the modified /// stat value.</param> /// <returns>The modified stat value.</returns> public static int Calculate <TStatType>(IStatCollection <TStatType> baseStats, TStatType statType, params IModStatContainer <TStatType>[] modders) where TStatType : struct, IComparable, IConvertible, IFormattable { int value = (int)baseStats[statType]; if (modders == null || modders.Length == 0) { return(value); } foreach (var modder in modders) { value += modder.GetStatModBonus(statType); } return(value); }
/// <summary> /// Handles the <see cref="IStatCollection{T}.StatChanged"/> event for the stat collections in this class. /// </summary> void StatCollection_StatChanged(IStatCollection<StatType> sender, StatCollectionStatChangedEventArgs<StatType> e) { Debug.Assert(sender.StatCollectionType != StatCollectionType.Modified, "ItemEntity does not use StatCollectionType.Modified."); var field = e.StatType.GetDatabaseField(sender.StatCollectionType); SynchronizeField(field, e.NewValue); }
protected override void RaiseStatModified(IStatCollection <StatType> stats, StatType statType) { }
protected virtual void RaiseEvent(IStatCollection <StatType> col, StatType type) { StatModified?.Invoke(this, type); }
public void SetUp() { _speedStat = MockRepository.GenerateMock<ISpeedStat>(); _statCollection = MockRepository.GenerateMock<IStatCollection>(); _role = MockRepository.GenerateMock<IRole>(); _statCollectionBuilder = MockRepository.GenerateMock<IStatCollectionBuilder>(); _testObject = new DodgeballPlayer(_role, _statCollectionBuilder); }
/// <summary> /// Initializes a new instance of the <see cref="StatCollection{StatType}"/> class. /// </summary> /// <param name="source">The <see cref="StatCollection{StatType}"/> to copy the values from.</param> public StatCollection(IStatCollection <TStatType> source) : this(source.StatCollectionType, source) { }
/// <summary> /// Checks if this <see cref="IStatCollection{TStatType}"/> contains the same stat values as another /// <see cref="IStatCollection{TStatType}"/> for the respective stat type. /// </summary> /// <param name="other">The <see cref="IStatCollection{TSstatType}"/> to compare against.</param> /// <returns>True if this <see cref="IStatCollection{TStatType}"/> contains the same values as the /// <paramref name="other"/> for the respective stat type; otherwise false.</returns> public bool HasSameValues(IStatCollection <TStatType> other) { return(other.All(x => this[x.StatType] == x.Value)); }
/// <summary> /// Handles when the <see cref="Character"/>'s base stats change. /// </summary> /// <param name="sender">The <see cref="IStatCollection{TStatType}"/> the event came from.</param> /// <param name="e">The <see cref="StatCollectionStatChangedEventArgs{StatType}"/> instance containing the event data.</param> void BaseStatChangedHandler(IStatCollection<StatType> sender, StatCollectionStatChangedEventArgs<StatType> e) { _updateModStats = true; OnBaseStatChanged(e.StatType, e.OldValue, e.NewValue); }
/// <summary> /// Handles when the <see cref="Character"/>'s mod stats change. /// </summary> /// <param name="sender">The <see cref="IStatCollection{TStatType}"/> the event came from.</param> /// <param name="e">The <see cref="StatCollectionStatChangedEventArgs{StatType}"/> instance containing the event data.</param> void ModStatChangedHandler(IStatCollection<StatType> sender, StatCollectionStatChangedEventArgs<StatType> e) { _updateModStats = true; // Ensure the HP and MP are valid switch (e.StatType) { case StatType.MaxMP: if (MP > e.NewValue) MP = (int)e.NewValue; break; case StatType.MaxHP: if (HP > e.NewValue) HP = (int)e.NewValue; break; } // Update the attack rate if (e.StatType == StatType.Agi) _attackTimeout = Math.Max(GameData.AttackTimeoutMin, GameData.AttackTimeoutDefault - ModStats[StatType.Agi] * 2); OnModStatChanged(e.StatType, e.OldValue, e.NewValue); }