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

public class LandRewardControl : MonoBehaviour
{
    public int position = -1;
    public GameObject getFruit;
    public GameObject getFruit2;
    public LandDataControl mLandData;
    private int fruitNum = 0;

    //private LandListEvent landEvent;
    private FarmControl landFarm;
    private void Awake()
    {
        //landEvent = GameObject.Find("Form_land")?.GetComponent<LandListEvent>();
        landFarm = GameObject.Find("Form_land")?.GetComponent<FarmControl>();
    }
    private void Start()
    {
        updateFruitNum();
    }
    public int getFruitNum
    {
        get { return fruitNum; }
    }

    public void updateFruitNum()
    {
        if (position != -1)
        {
            //fruitNum = LandListDataControl.GetIns().getFruitNum(position);
            fruitNum = mLandData.getMyLandEntity.fruitNum;
        }
    }
    //收获水果
    public void onClickRewardFruit()
    {
        if (position != -1)
        {
            landFarm.setOnclickLandId = position;
            GameObject.Find("Music_Background").GetComponent<MusicPlayerControl>().playBtnAudio();
            GameObject.Find("GameManager").GetComponent<UnityToAndroid>().onEventUtil("click_reward_farm_id_" + (position + 1), "收获农作物id_" + (position + 1));
            if (mLandData.setRewardFruitData(position))
            {
                fruitNum++;
                //GameObject.Find("Form_land")?.GetComponent<LandListEvent>().updateLandList();
                getFruit.SetActive(true);
                getFruit2.SetActive(true);
                GameObject.Find("guideParent").GetComponent<UserGuide>().setStep3();
                GameObject.Find("Form_land")?.GetComponent<LandListEvent>().updateLandList(3, position,0);
            }
            else
            {
                Debug.Log("收获水果失败");
            }
        }
    }
}
