using ScrambleKit.Hits;
using UnityEngine;

public class ChomperBody : MonoBehaviour 
{
    public float RoomUse=0.6f;
    public float BaseSpeed = 2f;
    public float SpeedPerHeadLost = 2f;
    public float BaseAttackInterval = 2.5f;
    public float IntervalCutHerHeadLost = 0.5f;

    private int headCount = 4;

    private EnemyMovementController move;
    private AIPattern pattern;

    void Start()
    {
        move = GetComponent<EnemyMovementController>();
        pattern = GetComponent<AIPattern>();
    }

    private void ChooseNewSpot(EnemyMovementController move)
    {
        move.TargetPos = new Vector2(
            Random.Range(-RoomSize.Width * RoomUse, RoomSize.Width * RoomUse),
            Random.Range(-RoomSize.Height * RoomUse, RoomSize.Height * RoomUse)
        );
    }

    public void LostHead()
    {
        headCount--;
        if(headCount == 0)
        {
            KillYourself();
        }
        else
        {
            move.SpeedLimit = BaseSpeed + (4 - headCount) * SpeedPerHeadLost;
            pattern.AttackInterval = BaseAttackInterval - (4 - headCount) * IntervalCutHerHeadLost;
        }
    }

    private void KillYourself()
    {
        HitInfo hit = new HitInfo();
        hit.Damage = 999;
        transform.SendMessage("TakeHit", hit);
    }
}
