using MyCollections.DesignPatterns.Visitor; using MyCollections.Stats; using System.Collections; using System.Collections.Generic; using UnityEngine; using System; [CreateAssetMenu(menuName = "Item/Potion")] public class StatPotion : Item, IVisitor { 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; public void Visit<T>(T visitable) where T : Component, IVisitable { if (visitable is PlayerController controller) { ApplyStatsEffect(controller); } } private void ApplyStatsEffect(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); Debug.Log($"Added modifier: {modifier}"); } }