Exemple #1
0
    private int StopTimerIntern(string key, string timeKey)
    {
        int time = -1;

        dataLock.WaitOne();

        Stopwatch timer = (Stopwatch)dataStore[key];

        timer.Stop();
        dataStore.Remove(key);

        time = (int)timer.ElapsedMilliseconds;
        if (timeKey != null)
        {
            dataStore[timeKey] = time;
        }

        dataLock.ReleaseMutex();

        if (StatChanged != null)
        {
            StatChanged.Invoke();
        }

        return(time);
    }
        /// <summary>
        /// Gets or sets the value of the stat of the given <paramref name="statType"/>.
        /// </summary>
        /// <param name="statType">The type of the stat to get or set the value of.</param>
        /// <returns>The value of the stat of the given <paramref name="statType"/>.</returns>
        public StatValueType this[TStatType statType]
        {
            get { return(_stats[statType]); }
            set
            {
                // Get the stat value
                var oldValue = _stats[statType];

                // Ensure the value has changed
                if (oldValue == value)
                {
                    return;
                }

                // Set the new value
                _stats[statType] = value;

                // Raise the event
                OnStatChanged(statType, oldValue, value);

                if (StatChanged != null)
                {
                    StatChanged.Raise(this, new StatCollectionStatChangedEventArgs <TStatType>(statType, oldValue, value));
                }
            }
        }
Exemple #3
0
        public virtual async Task Fill()
        {
            var original = Value;

            Value = Base;

            if (StatChanged != null)
            {
                await StatChanged.Invoke(this, original);
            }
        }
Exemple #4
0
        public virtual async Task ApplyAsync(int modifier)
        {
            var original = Value;

            Value += modifier;

            Value = Math.Clamp(Value, Minimum, Base);

            if (StatChanged != null)
            {
                await StatChanged.Invoke(this, original);
            }
        }
Exemple #5
0
 /// <summary>
 /// Invokes the stat changed event with the given parameters
 /// </summary>
 /// <param name="caller">The object performing the call</param>
 /// <param name="args">The <see cref="SurvivalStatChangedEventArgs" /> instance containing the event data.</param>
 public void InvokeStatChangedEvent(SurvivalModuleBase caller, SurvivalStatChangedEventArgs args)
 {
     StatChanged?.Invoke(caller, args);
 }
Exemple #6
0
 public void InvokeStatChange(StatsType t, object val, bool updateSelfOnly = false)
 {
     StatChanged?.Invoke(this, new StatChangedEventArgs(t, val, updateSelfOnly));
 }
Exemple #7
0
        /// <summary>
        /// Increases the stat of the player character. The increase will go with the Triangular
        /// number formula, n(n + 1) / 2, so to increase the stat from 0 to 5, you would need to
        /// input 15 into the function. Any remainding numbers will be stored into a buffer and
        /// included in the computation on the next time the stat is increased.
        /// </summary>
        /// <param name="stat">The stat to increase.</param>
        /// <param name="value">The factor in which to increase the stat.</param>
        public void IncreaseStat(Stat stat, uint value)
        {
            StatChangedEventArgs e;

            switch (stat)
            {
            case Stat.Strength:
                e = new StatChangedEventArgs(Stat.HealthMax, this.HealthMax);

                this.IncreaseStat(
                    ref this.strength,
                    Stat.Strength,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Intelligence:
                e = new StatChangedEventArgs(Stat.ManaMax, this.ManaMax);

                this.IncreaseStat(
                    ref this.intelligence,
                    Stat.Intelligence,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Agility:
                e = new StatChangedEventArgs(Stat.StaminaMax, this.StaminaMax);

                this.IncreaseStat(
                    ref this.agility,
                    Stat.Agility,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Vitality:
                StatChangedEventArgs e1 = new StatChangedEventArgs(Stat.HealthMax, this.HealthMax);
                StatChangedEventArgs e2 = new StatChangedEventArgs(Stat.StaminaMax, this.StaminaMax);

                this.IncreaseStat(
                    ref this.vitality,
                    Stat.Vitality,
                    value,
                    () =>
                {
                    StatChanged?.Invoke(this, e1);
                    StatChanged?.Invoke(this, e2);
                });
                break;

            case Stat.Luck:
                this.IncreaseStat(ref this.luck, Stat.Luck, value, null);
                break;

            case Stat.WeaponUse:
                this.IncreaseStat(ref this.weaponUse, Stat.WeaponUse, value, null);
                break;

            case Stat.Parry:
                this.IncreaseStat(ref this.parry, Stat.Parry, value, null);
                break;

            case Stat.Dodge:
                this.IncreaseStat(ref this.dodge, Stat.Dodge, value, null);
                break;

            case Stat.Stealth:
                this.IncreaseStat(ref this.stealth, Stat.Stealth, value, null);
                break;

            case Stat.LockPicking:
                this.IncreaseStat(ref this.lockPicking, Stat.LockPicking, value, null);
                break;

            case Stat.Throwing:
                this.IncreaseStat(ref this.throwing, Stat.Throwing, value, null);
                break;

            case Stat.Climbing:
                this.IncreaseStat(ref this.climbing, Stat.Climbing, value, null);
                break;

            case Stat.Magic:
                e = new StatChangedEventArgs(Stat.ManaMax, this.ManaMax);

                this.IncreaseStat(
                    ref this.magic,
                    Stat.Magic,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Health:
            case Stat.HealthMax:
            case Stat.Stamina:
            case Stat.StaminaMax:
            case Stat.Mana:
            case Stat.ManaMax:
            case Stat.Humans:
            case Stat.Sidhe:
            case Stat.Giants:
                throw new NotImplementedException(
                          $"Enum {stat} is not intended to be set here, use property instead.");

            default:
                throw new InvalidEnumArgumentException(nameof(stat), (int)stat, typeof(Stat));
            }
        }
 protected void OnStatChanged(int value)
 {
     StatChanged?.Invoke(value);
 }