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

public class CharacterAgeBehaviour : MonoBehaviour
{
    public GameObject olderCharacterPrefab;
    private MovementController movementController;
    public MovementController newMovementController;

    // Start is called before the first frame update
    void Start()
    {
        movementController = GetComponent<MovementController>();
    }

    /// <summary>
    /// If an 'older' character exists, replace this character with a new copy of that character
    /// Hand over any held item!
    /// </summary>
    public bool AttemptAgeCharacter(){
        if (olderCharacterPrefab != null)
        {
            GameObject character = Instantiate(olderCharacterPrefab, transform.position, Quaternion.identity, transform.parent);

            newMovementController = character.GetComponent<MovementController>();

            if (movementController.IsHoldingItem())
            { //perform item handover
                Transform item = movementController.heldItem;
                movementController.DropItem();
                newMovementController.GiveItem(item);
            }

            return true;
        }

        else return false;
    }



}
