コード例 #1
0
    public StatusEffect(StatusEffectScriptableObject data, TickTime tickTime, int duration)
    {
        this.data = ScriptableObject.Instantiate <StatusEffectScriptableObject>(data);

        this.tickTime     = tickTime;
        durationRemaining = duration;
    }
コード例 #2
0
    public void AfflictWithStatusEffect(StatusEffectScriptableObject effectSO, int duration)
    {
        if (IsDead)
        {
            return;
        }

        if (IsImmuneToDebuffs())
        {
            if (effectSO.type == StatusEffectScriptableObject.Type.Disable || effectSO.type == StatusEffectScriptableObject.Type.Poison)
            {
                Animator.SetTrigger("Block");
                DamageNumberCanvas canva = GameObject.Instantiate(FindObjectOfType <CombatManager>().damageNumberCanvasPrefab).GetComponent <DamageNumberCanvas>();
                canva.Display("Immune", Color.magenta);
                canva.transform.position = transform.position;
                return;
            }
        }

        StatusEffect.TickTime tickTime = StatusEffect.TickTime.TurnStart;

        if (FindObjectOfType <CombatManager>().turn == CombatManager.TurnSelection.Enemies)
        {
            if (this is PlayerCombatObject)
            {
                tickTime = StatusEffect.TickTime.TurnEnd;
            }
        }

        StatusEffect effect = new StatusEffect(effectSO, tickTime, duration);

        StatusEffects.Add(effect);

        DamageNumberCanvas canv = GameObject.Instantiate(FindObjectOfType <CombatManager>().damageNumberCanvasPrefab).GetComponent <DamageNumberCanvas>();

        canv.Display("Applying: " + effect.data.name, Color.green);
        canv.transform.position = transform.position;

        foreach (var behaviour in effect.data.behaviour)
        {
            if (effect.tickTime == StatusEffect.TickTime.TurnStart)
            {
                OnStartTurn += behaviour.TickPerTurn;
            }
            else
            {
                OnEndTurn += behaviour.TickPerTurn;
            }
            OnAttackedBehaviour += behaviour.OnAttacked;
            behaviour.OnAfflicted(this);
        }

        RefreshUI();
    }