using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Machete {
	public class Applied : Student {

    [SerializeField]
    private int tolerance;
    private int curTolerance;

    [SerializeField]
    private int ticksToRecover = 1;
    private int ticksCount;

    protected override void Start() {
      base.Start();
      curTolerance = tolerance;
      Ticker.Instance.OnTick += RecoverTolerance;
    }

    public override bool TakeMessage(Message message) {
      // Me don't want your message.
      if (curTolerance == 0) {
        return false;
      }
      curTolerance--;
      return true;
    }

    void RecoverTolerance() {
      ticksCount++;
      if (ticksToRecover - 1 > ticksCount) {
        return;
      }
      ticksCount = 0;
      curTolerance++;
      curTolerance = Mathf.Min(curTolerance, tolerance);
    }
	}
}
