コード例 #1
0
ファイル: Plant.cs プロジェクト: LapisRaider/TaikaiGamejam
    public void Init(PlantScriptableObj plantScript, Vector2Int plantGridPos)
    {
        m_GrowthTime        = plantScript.m_GrowthTime;
        m_PlantTime         = plantScript.m_PlantTime;
        m_TemperatureToGrow = plantScript.m_TemperatureToGrow;
        m_CurrentHealth     = plantScript.m_PlantHealth;

        m_PlantGridPos = plantGridPos;

        m_PlantType = plantScript.m_PlantType;

        //set sprite stuff
        m_SpriteRenderer.sprite       = plantScript.m_PlantSprite;
        m_SpriteRenderer.color        = Color.white;
        m_SpriteRenderer.sortingOrder = (int)(transform.position.y * -100);

        m_Dead = false;
        if (m_Animator != null)
        {
            m_Animator.ResetTrigger("Shaking");
            m_Animator.ResetTrigger("Dying");
        }

        Temperature temperature = GameStats.Instance.m_Temperature;

        if (temperature != null)
        {
            CheckTemperatureUpdate(temperature.m_CurrTempType);
        }
    }
コード例 #2
0
    public bool HaveInInventory(Plant_Types plantType)
    {
        if (m_Inventory == null)
        {
            return(false);
        }

        return(m_Inventory.HaveInInventory(plantType));
    }
コード例 #3
0
    public PlantScriptableObj GetPlantData(Plant_Types plantType)
    {
        if (m_PlantDictionary.ContainsKey(plantType))
        {
            return(m_PlantDictionary[plantType]);
        }

        return(null);
    }
コード例 #4
0
    public void InitType(Plant_Types type, Vector2Int gridPos, Plant plant)
    {
        if (!m_PlantDataBase.m_PlantDictionary.ContainsKey(type))
        {
            return;
        }

        plant.Init(m_PlantDataBase.m_PlantDictionary[type], gridPos);
    }
コード例 #5
0
    public int GetAmtOfPlantOnMap(Plant_Types plantType)
    {
        if (plantType < Plant_Types.FLOWERS)
        {
            return(GetAmtOfTreeTypeOnMap(plantType));
        }

        return(GetAmtOfPlantTypeOnMap(plantType));
    }
コード例 #6
0
    public int GetAmtInInventory(Plant_Types plantType)
    {
        //dont have in inventory
        if (!m_PlantInventory.ContainsKey(plantType))
        {
            return(0);
        }

        return(m_PlantInventory[plantType]);
    }
コード例 #7
0
    public void BuyOneIntoInventory(Plant_Types plantType)
    {
        if (m_PlantInventory.ContainsKey(plantType))
        {
            m_PlantInventory[plantType] += 1;
            return;
        }

        //if not add it into inventory
        m_PlantInventory.Add(plantType, 1);
    }
コード例 #8
0
    public bool RemoveOneFromInventory(Plant_Types plantType)
    {
        if (!m_PlantInventory.ContainsKey(plantType))
        {
            return(false);
        }

        //remove it from the inventory if there arent anymore
        m_PlantInventory[plantType] -= 1;
        if (m_PlantInventory[plantType] <= 0)
        {
            m_PlantInventory.Remove(plantType);
        }

        return(true);
    }
コード例 #9
0
    public int GetAmtOfPlantTypeOnMap(Plant_Types plantType)
    {
        int amt = 0;

        foreach (KeyValuePair <Vector2Int, Plant> tree in m_PlantOnMap)
        {
            if (tree.Value == null)
            {
                continue;
            }

            if (tree.Value.m_PlantType == plantType)
            {
                ++amt;
            }
        }

        return(amt);
    }
コード例 #10
0
    public void Init()
    {
        PlantScriptableObj plantData = MapManager.Instance.GetPlantDataBase().GetPlantData(m_PlantType);

        if (plantData == null)
        {
            return;
        }

        m_Price     = plantData.m_Price;
        m_PlantType = plantData.m_PlantType;

        m_PlantNameText.text       = plantData.m_PlantName;
        m_PlantDesriptionText.text = plantData.m_PlantDescription;

        switch (plantData.m_TemperatureToGrow)
        {
        case TemperatureType.EXTREMELY_HOT:
            m_TemperatureToGrowText.text = "Can survive all temperatures";
            break;

        case TemperatureType.VERY_HOT:
            m_TemperatureToGrowText.text = "Survive Scorch and below";
            break;

        case TemperatureType.HOT:
            m_TemperatureToGrowText.text = "Survive hot and below";
            break;

        case TemperatureType.NICE:
            m_TemperatureToGrowText.text = "Survive only nice temperature";
            break;
        }

        m_PlantPrice.text    = "Price: $" + m_Price.ToString() + " per seed";
        m_MaxPlant           = plantData.m_MaxNumberToPlant;
        m_SpriteImage.sprite = plantData.m_PlantSprite;
    }
コード例 #11
0
 //check if there are any available in the inventory
 public bool HaveInInventory(Plant_Types plantType)
 {
     return(m_PlantInventory.ContainsKey(plantType));
 }
コード例 #12
0
    public float Plant(Vector2Int tilePos)
    {
        //gets a random available plant type
        Inventory   inventory = GameStats.Instance.m_Inventory;
        Plant_Types type      = GameStats.Instance.GetAvilablePlantType();
        bool        isTree    = type < Plant_Types.FLOWERS;

        if (!inventory.HaveInInventory(type))
        {
            return(0.0f);
        }

        if (isTree)
        {
            if (m_TreeOnMap.ContainsKey(tilePos))
            {
                return(0.0f);
            }

            //plant tree
            GameObject treeObj = m_PlantManager.GetAndSpawnTree();
            if (treeObj == null)
            {
                return(0.0f);
            }

            treeObj.transform.position = m_MapGrid.GetCellCenterWorld((Vector3Int)tilePos);
            treeObj.SetActive(true);

            PlantTree plantTree = treeObj.GetComponent <PlantTree>();
            if (plantTree)
            {
                m_PlantManager.InitType(type, tilePos, plantTree);
                m_TreeOnMap.Add(tilePos, plantTree);

                inventory.RemoveOneFromInventory(type); //remove one from inventory
                GameStats.Instance.UpdateCurrentPlantNumber(isTree, m_TreeOnMap.Count);

                return(plantTree.m_PlantTime);
            }
        }
        else
        {
            if (m_PlantOnMap.ContainsKey(tilePos))
            {
                return(0.0f);
            }

            //plant plants
            GameObject plantObj = m_PlantManager.GetAndSpawnPlant();
            if (plantObj == null)
            {
                return(0.0f);
            }

            plantObj.transform.position = m_MapGrid.GetCellCenterWorld((Vector3Int)tilePos);
            plantObj.SetActive(true);

            Plant plantedPlant = plantObj.GetComponent <Plant>();
            if (plantedPlant)
            {
                m_PlantManager.InitType(type, tilePos, plantedPlant);
                m_PlantOnMap.Add(tilePos, plantedPlant);

                inventory.RemoveOneFromInventory(type); //remove one from inventory
                GameStats.Instance.UpdateCurrentPlantNumber(isTree, m_PlantOnMap.Count);

                return(plantedPlant.m_PlantTime);
            }
        }

        return(0.0f);
    }