Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / Items / Potions / StatModifierPotion.cs
@Rackday Rackday on 29 Oct 957 bytes Major Update
using MyCollections.Stats;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "Item/Potion")]
public class StatModifierPotion : Potion
{
    public enum OperatorType { Add, Multiply }

    [SerializeField] private StatType statType = StatType.Attack;
    [SerializeField] private OperatorType operatorType = OperatorType.Add;
    [SerializeField] private int value = 10;
    [SerializeField] private float duration = 5f;

    protected override void ApplyPotionEffect(PlayerController controller)
    {
        StatModifier modifier = operatorType switch
        {
            OperatorType.Add => new BasicStatModifier(statType, duration, v => v + value),
            OperatorType.Multiply => new BasicStatModifier(statType, duration, v => v * value),
            _ => throw new ArgumentOutOfRangeException()
        };

        controller.Stats.Mediator.AddModifier(modifier);
    }
}