Example #1
0
    void OnCTRWillChange(object sender, object args)
    {
        ValueChangeException exc = args as ValueChangeException;
        MultDeltaModifier    mod = new MultDeltaModifier(0, 2);

        exc.AddModifier(mod);
    }
Example #2
0
    void OnCRTWillChange(object sender, object args)
    {
        ValueChangeException exc = args as ValueChangeException;
        MultDeltaModifier    m   = new MultDeltaModifier(0, 1.10f);

        exc.AddModifier(m);
    }
Example #3
0
File: Stats.cs Project: zuig/MyRPG
    public void SetValue(StatTypes type, int value, bool allowExceptions)
    {
        int oldValue = this[type];
        if (oldValue == value)
            return;

        if (allowExceptions)
        {
            // Allow exceptions to the rule here
            ValueChangeException exc = new ValueChangeException( oldValue, value );

            // The notification is unique per stat type
            this.PostNotification(WillChangeNotification(type), exc);

            // Did anything modify the value?
            value = Mathf.FloorToInt(exc.GetModifiedValue());

            // Did something nullify the change?
            if (exc.toggle == false || value == oldValue)
                return;
        }

        _data[(int)type] = value;
        this.PostNotification(DidChangeNotification(type), oldValue);
    }
Example #4
0
    public void SetValue(StatTypes type, int value, bool allowExceptions)
    {
        int oldValue = this[type];

        if (oldValue == value)
        {
            return;
        }

        if (allowExceptions)
        {
            // Allow exceptions to the rule here
            ValueChangeException exc = new ValueChangeException(oldValue, value);

            // The notification is unique per stat type
            this.PostNotification(WillChangeNotification(type), exc);

            // Did anything modify the value?
            value = Mathf.FloorToInt(exc.GetModifiedValue());

            // Did something nullify the change?
            if (exc.toggle == false || value == oldValue)
            {
                return;
            }
        }

        _data[(int)type] = value;
        this.PostNotification(DidChangeNotification(type), oldValue);
    }
Example #5
0
    void OnExperienceException(object sender, object args)
    {
        GameObject           actor = (sender as Stats).gameObject;
        ValueChangeException vce   = args as ValueChangeException;
        int roll = UnityEngine.Random.Range(0, 5);

        switch (roll)
        {
        case 0:
            vce.FlipToggle();
            Debug.Log(string.Format("{0} would have received {1} experience, but we stopped it", actor.name, vce.delta));
            break;

        case 1:
            vce.AddModifier(new AddValueModifier(0, 1000));
            Debug.Log(string.Format("{0} would have received {1} experience, but we added 1000", actor.name, vce.delta));
            break;

        case 2:
            vce.AddModifier(new MultValueModifier(0, 2f));
            Debug.Log(string.Format("{0} would have received {1} experience, but we multiplied by 2", actor.name, vce.delta));
            break;

        default:
            Debug.Log(string.Format("{0} will receive {1} experience", actor.name, vce.delta));
            break;
        }
    }
Example #6
0
    public void SetValue(StatTypes type, int value, bool allowExceptions)
    {
        int oldValue = this [type];

        if (oldValue == value)
        {
            return;
        }

        if (allowExceptions)
        {
            ValueChangeException exc = new ValueChangeException(oldValue, value);

            this.PostNotification(WillChangeNotification(type), exc);

            value = Mathf.FloorToInt(exc.GetModifiedValue());

            if (exc.toggle == false || value == oldValue)
            {
                return;
            }
        }

        _data [(int)type] = value;
        this.PostNotification(DidChangeNotification(type), oldValue);
    }
    void OnStatCounterWillChange(object sender, object args)
    {
        // Dont allow a KO'd unit to increment the turn order counter
        ValueChangeException exc = args as ValueChangeException;

        if (exc.toValue > exc.fromValue)
        {
            exc.FlipToggle();
        }
    }
    private void OnStatCounterWillChange(object sender, object args)
    {
        // KO'd unit gains no turn counter
        ValueChangeException exc = args as ValueChangeException;

        if (exc.toValue > exc.fromValue)
        {
            exc.FlipToggle();
        }
    }
Example #9
0
    public void SetValue(StatTypes type, int value, bool allowExceptions)
    {
        int oldVlaue = this [type];
        if (oldVlaue == value)
            return;

        if (allowExceptions) {
            ValueChangeException exc = new ValueChangeException(oldVlaue, value);
            this.PostNotification (WillChangeNotification(type), exc);
            value = Mathf.FloorToInt (exc.GetModifiedValue());

            if(exc.toggle == false || value == oldVlaue)
                return;
        }

        _data [(int)type] = value;
        this.PostNotification (DidChangeNotification (type), oldVlaue);
    }
Example #10
0
File: Stats.cs Project: swejk/2DRPG
    public void SetValue(StatTypes s, float value, bool allowExceptions)
    {
        float oldValue = this[s];
        if (oldValue == value)
        {
            return;
        }

        if (allowExceptions)
        {
            ValueChangeException ve = new ValueChangeException(oldValue, value);
            this.PostNotification(WillChangeNotification(s), ve);
            value = Mathf.FloorToInt(ve.GetModifiedValue());
            if (ve.toggle == false || oldValue == value)
            {
                return;
            }
        }
        
        _data[(int)s] = value;
        this.PostNotification(DidChangeNotification(s), oldValue);
    }
Example #11
0
    // handler method for speed counter notification
    void OnCounterWillChange(object sender, object args)
    {
        ValueChangeException exc = args as ValueChangeException;

        exc.FlipToggle();
    }
Example #12
0
    void OnHPWillChange(object sender, object args)
    {
        ValueChangeException vce = args as ValueChangeException;

        vce.AddModifier(new ClampValueModifier(int.MaxValue, MinHP, stats[StatTypes.MHP]));
    }
Example #13
0
    void OnExpWillChange(object sender, object args)
    {
        ValueChangeException vce = args as ValueChangeException;

        vce.AddModifier(new ClampValueModifier(int.MaxValue, EXP, maxExperience));
    }
Example #14
0
    public float SetValue(StatTypes type, float value, bool allowExceptions)
    {
        float oldValue = this[type];

        if (allowExceptions)
        {
            // Allow exceptions to the rule here
            ValueChangeException exc = new ValueChangeException(oldValue, value);

            // The notification is unique per stat type
            this.PostNotification(WillChangeNotification(type), exc);

            // Did anything modify the value?
            value = Mathf.FloorToInt(exc.GetModifiedValue());

            // Did something nullify the change?
            if (exc.toggle == false || value == oldValue)
            {
                return(oldValue);
            }
        }


        if (oldValue == value)
        {
            return(oldValue);
        }

        // Modify value for special cases (ie Health/Mana will not go lower than 0, or higher than MHP/MMP)
        switch (type)
        {
        case StatTypes.HP:
            value = Mathf.Clamp(value, 0, this[StatTypes.MHP]);
            break;

        case StatTypes.MP:
            value = Mathf.Clamp(value, 0, this[StatTypes.MMP]);
            break;
        }

        // Set Value
        _data[(int)type] = value;

        // Wrap up other stat changes affected by value, and send completed notifications
        if (type == StatTypes.DEX)
        {
            if (_data[(int)type] <= 0)
            {
                _data[(int)StatTypes.SPD] = 0;
            }
            else
            {
                _data[(int)StatTypes.SPD] = 1 / _data[(int)type] / 2;
            }
        }


        this.PostNotification(DidChangeNotification(type), oldValue);
        this.PostNotification(UnitUpdateNotification, GetComponent <Unit>());
        return(value);
    }
Example #15
0
    void OnExpWillChange(object sender, object args)
    {
        ValueChangeException vce = args as ValueChangeException;

        vce.AddModifier(new ClampValueModifier(int.MaxValue, EXP, maxExperience)); //the highest possible sort order (to make sure it is the last modifier to be applied)
    }