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

public class MagnetPowerUpEffect : PowerUpEffect
{
    private GameObject _player;
    private PlayerObjectShared _playerObjectShared;
    public GameObject coredVersionGO;

    // Start is called before the first frame update
    void Start()
    {
        _currentGameEngine = FindObjectOfType<GameEngine>();
        _player = GameEngine.mainPlayer;
        _playerObjectShared = _player.GetComponent<PlayerObjectShared>();
    }

    public override void OnPickUp()
    {
        Transform coreHolder = _player.transform.Find("PlayerModel/CoreHolder");
        for (int i = 0; i < coreHolder.transform.childCount; i++)
        {
            Destroy(coreHolder.GetChild(i).gameObject);
        }
        GameObject newSpecialCore = Instantiate(coredVersionGO, coreHolder);        
        AttachablePowerUpEffect newMagnetEffect = newSpecialCore.GetComponent<MagnetAttachedPowerUpEffect>();
        _playerObjectShared.AttachPickUp(newMagnetEffect);

        if (_currentGameEngine != null)
        {
            _currentGameEngine.QueueDialog(dialogIndex);
        }
    }

    public override void ApplyEffect()
    {        
    }
}
