Esempio n. 1
0
    private void Awake()
    {
        statuses = new List <IStatus>(10);
        Updater  = NormalUpdate;

        attrModifiable = GetComponent <IAttrModifierTaker>();
        combater       = GetComponent <ICombater>();

        Reporter.ComponentMissingCheck(attrModifiable);
        Reporter.ComponentMissingCheck(combater);
    }
Esempio n. 2
0
    /// <summary>
    /// Initialize a status based on StatusTpl, PeriodCombatResouceEffect and AttrModifierEffect.
    /// Then bind the status to the taker.
    /// </summary>
    /// <param name="_source"></param>
    /// <param name="stack"></param>
    /// <param name="timePercent"></param>
    /// <returns></returns>
    public static IStatus Create(SOStatusTpl template,
                                 IAttrModifierTaker attrModifierTaker,
                                 ICombater combatTaker,
                                 IAttrHolder applierAttr,
                                 int stack = 1, float timePercent = 1)
    {
        // retrieve from scriptable object
        StatusTpl _source = template.StatusTpl;

        // clear lists
        updatables.Clear();
        stackables.Clear();

        // initialize combat resource effect processor
        if (combatTaker != null && _source.CombatPeriodEffects.Length != 0)
        {
            PeriodicCombatResourceEffect _combatResourceEffect = new PeriodicCombatResourceEffect(_source.CombatPeriodEffects, combatTaker, applierAttr, CombatResourceEffectExecutor.Instance);
            updatables.Add(_combatResourceEffect);
            stackables.Add(_combatResourceEffect);
        }

        // initialize attr modifier effect processor
        if (attrModifierTaker != null && _source.AttrModifiers.Length != 0)
        {
            AttrModifierEffect _attrModifierEffect = new AttrModifierEffect(_source.AttrModifiers, attrModifierTaker);
            stackables.Add(_attrModifierEffect);
        }

        // build constructor parameters
        IStatusUpdatable[] _updatables = updatables.Count == 0 ? emptyUpdatable : updatables.ToArray();
        IStatusStackable[] _stackables = stackables.Count == 0 ? emptyStackable : stackables.ToArray();

        // build status
        Status _status = new Status(_source, template.GetInstanceID(), _updatables, _stackables, stack, Mathf.Max(0, timePercent));

        return(_status);
    }
Esempio n. 3
0
    /// <summary>
    /// Calculate the power of fixed power + linked power + percent power,
    /// and apply corresponding effects to the taker
    /// </summary>
    public void TakeEffect(CombatResourceEffectTpl combatResourceEffect, IAttrHolder applierAttr, ICombater taker, int multiplier = 1)
    {
        // get fixed power
        float _power = combatResourceEffect.FixedPower;

        // get percent power
        if (taker != null)
        {
            switch (combatResourceEffect.Type)
            {
            case ECombatResourceEffectType.HealthGain:
            case ECombatResourceEffectType.HealthLose:
            case ECombatResourceEffectType.Damage:
                _power += combatResourceEffect.PercentPower * taker.MaxHealth;
                break;

            case ECombatResourceEffectType.Heal:
            case ECombatResourceEffectType.ManaGain:
            case ECombatResourceEffectType.ManaLose:
                _power += combatResourceEffect.PercentPower * taker.MaxMana;
                break;
            }
        }

        // get linked power
        if (applierAttr != null)
        {
            for (int i = 0; i < combatResourceEffect.ApplierAttrLinks.Length; ++i)
            {
                float _attr = applierAttr.GetAttr(combatResourceEffect.ApplierAttrLinks[i].LinkedType);
                _power += _attr * combatResourceEffect.ApplierAttrLinks[i].Percent;
            }
        }

        // take multiplier
        _power = _power * Mathf.Max(0, multiplier);

        // take effects
        switch (combatResourceEffect.Type)
        {
        case ECombatResourceEffectType.HealthGain:
            taker.ModifyHealth(_power, false);
            break;

        case ECombatResourceEffectType.HealthLose:
            taker.ModifyHealth(-_power, false);
            break;

        case ECombatResourceEffectType.Damage:
            taker.TakeDamage(_power, false, canDodge: false);
            break;

        case ECombatResourceEffectType.Heal:
            taker.TakeHeal(_power, false);
            break;

        case ECombatResourceEffectType.ManaGain:
            taker.ModifyMana(_power, false);
            break;

        case ECombatResourceEffectType.ManaLose:
            taker.ModifyMana(-_power, false);
            break;
        }
    }