public void actionClicked()
 {
     if (!b_haveAllObjectsRequired)
     {
         openBuyMenu();
     }
     else if (!b_areEnoughWorkers)
     {
         openHireMenu();
     }
     else
     {
         const int ID_SEND_HARVEST_TRAD   = 17;
         const int ID_SEND_HARVEST_MODERN = 29;
         if (m_actions[m_currentAction].id != ID_SEND_HARVEST_MODERN && m_actions[m_currentAction].id != ID_SEND_HARVEST_TRAD)
         {
             m_actions[m_currentAction].doMenuAction();
         }
         else
         {
             int  chunk       = ((ChunkAction)m_actions[m_currentAction]).chunk;
             uint riceInChunk = WorldTerrain.GetInstance().getRiceChunkProduction(chunk);
             if (!BuildingsManager.GetInstance().isBuilded(BUILDINGS.PLANTA))
             {
                 Building_Trill trill = (Building_Trill)BuildingsManager.GetInstance().getBuilding(BUILDINGS.TRILL);
                 uint           currentFreeCapacity = trill.getCurrentFreeCapacity();
                 if (currentFreeCapacity >= riceInChunk)
                 {
                     m_actions[m_currentAction].doMenuAction();
                 }
                 else
                 {
                     //uint possibleLost = riceInChunk - currentFreeCapacity;
                     GameObject panelTemplate = Resources.Load("Prefabs/RiceOverflowLostFocusLayer") as GameObject;
                     GameObject panelInstance = Instantiate(panelTemplate);
                     GameObject panel         = panelInstance.transform.FindChild("RiceOverflowPanel").gameObject;
                     panel.GetComponent <RiceOverflowPanelBehaviour>().init((MenuAction)m_actions[m_currentAction]);
                 }
             }
             else
             {
                 Building_Planta planta = (Building_Planta)BuildingsManager.GetInstance().getBuilding(BUILDINGS.PLANTA);
                 uint            currentFreeCapacity = planta.getCurrentFreeCapacity();
                 if (currentFreeCapacity >= riceInChunk)
                 {
                     m_actions[m_currentAction].doMenuAction();
                 }
                 else
                 {
                     //uint possibleLost = riceInChunk - currentFreeCapacity;
                     GameObject panelTemplate = Resources.Load("Prefabs/RiceOverflowLostFocusLayer") as GameObject;
                     GameObject panelInstance = Instantiate(panelTemplate);
                     GameObject panel         = panelInstance.transform.FindChild("RiceOverflowPanel").gameObject;
                     panel.GetComponent <RiceOverflowPanelBehaviour>().init((MenuAction)m_actions[m_currentAction]);
                 }
             }
         }
         kill();
     }
 }
    private bool loadBuildings()
    {
        string    file_path = "json/buildings";
        TextAsset file      = Resources.Load(file_path, typeof(TextAsset)) as TextAsset;

        if (file != null)
        {
            JSONNode N = JSON.Parse(file.text);
            foreach (BUILDINGS buildingID in Enum.GetValues(typeof(BUILDINGS)))
            {
                string buildingStr = buildingID.ToString();
                switch (buildingID)
                {
                case BUILDINGS.CASA:
                    _buildings [buildingID] = new Building_Home(N [buildingStr], buildingID);
                    break;

                case BUILDINGS.ESTABLO:
                    _buildings [buildingID] = new Building_Stable(N [buildingStr], buildingID);
                    break;

                //case BUILDINGS.GARAJE:
                //	_buildings [buildingID] = new Building_Garage(N [buildingStr], buildingID);
                //	break;
                case BUILDINGS.PLANTER:
                    _buildings [buildingID] = new Building_Planter(N [buildingStr], buildingID);
                    break;

                case BUILDINGS.TRILL:
                    _buildings [buildingID] = new Building_Trill(N [buildingStr], buildingID);
                    break;

                case BUILDINGS.ERA:
                    _buildings [buildingID] = new Building_Era(N [buildingStr], buildingID);
                    break;

                case BUILDINGS.SILO:
                    _buildings [buildingID] = new Building_Silo(N [buildingStr], buildingID);
                    break;

                case BUILDINGS.PLANTA:
                    _buildings [buildingID] = new Building_Planta(N [buildingStr], buildingID);
                    break;

                default:
                    _buildings [buildingID] = new Building(N [buildingStr], buildingID);
                    break;
                }
                _isBuilded [buildingID] = false;
            }
            return(true);
        }
        Debug.Log(file_path + " not loaded");
        return(false);
    }
Beispiel #3
0
    public void sendRiceToDry()
    {
        uint riceProduced = getRiceProduced();

        UserDataManager.GetInstance().addRiceProduced(riceProduced);
        UserDataManager.GetInstance().addRiceLost(getRiceLost());
        if (!BuildingsManager.GetInstance().isBuilded(BUILDINGS.PLANTA))
        {
            Building_Trill trill        = (Building_Trill)BuildingsManager.GetInstance().getBuilding(BUILDINGS.TRILL);
            uint           riceOverFlow = (uint)Math.Max((int)(riceProduced - trill.getCurrentFreeCapacity()), 0);
            UserDataManager.GetInstance().addRiceLost(riceOverFlow);
            trill.sendRice(riceProduced);
        }
        else
        {
            Building_Planta planta       = (Building_Planta)BuildingsManager.GetInstance().getBuilding(BUILDINGS.PLANTA);
            uint            riceOverFlow = Math.Max(riceProduced - planta.getCurrentFreeCapacity(), 0);
            UserDataManager.GetInstance().addRiceLost(riceOverFlow);
            planta.sendRice(riceProduced);
        }
        _harvestImg.SetActive(false);
    }
    public void save(BuildingManagerData buildingManagerData)
    {
        foreach (KeyValuePair <BUILDINGS, bool> builded in IsBuilded)
        {
            if (builded.Value)
            {
                BuildingData buildingData = new BuildingData();
                buildingData.ID = builded.Key;
                switch (builded.Key)
                {
                case BUILDINGS.CASA: {
                    Building_Home b = (Building_Home)getBuilding(builded.Key);
                    buildingData.i     = b.getRow();
                    buildingData.j     = b.getCol();
                    buildingData.Level = b.getCurrentLevel();
                }
                break;

                case BUILDINGS.ESTABLO: {
                    Building_Stable b = (Building_Stable)getBuilding(builded.Key);
                    buildingData.i     = b.getRow();
                    buildingData.j     = b.getCol();
                    buildingData.Level = b.getCurrentLevel();
                }
                break;

                //case BUILDINGS.GARAJE: {
                //        Building_Garage b = (Building_Garage)getBuilding(builded.Key);
                //        buildingData.i = b.getRow();
                //        buildingData.j = b.getCol();
                //        buildingData.Level = b.getCurrentLevel();
                //    }
                //    break;
                case BUILDINGS.PLANTER: {
                    Building_Planter b = (Building_Planter)getBuilding(builded.Key);
                    buildingData.i            = b.getRow();
                    buildingData.j            = b.getCol();
                    buildingData.Level        = b.getCurrentLevel();
                    buildingData.SpecialSlot1 = b.estaSembrat() ? 1 : 0;
                    buildingData.SpecialSlot2 = (int)b.DiesSembrat;
                    buildingData.SpecialSlot3 = (int)b.Plantes;
                }
                break;

                case BUILDINGS.TRILL: {
                    Building_Trill b = (Building_Trill)getBuilding(builded.Key);
                    buildingData.i            = b.getRow();
                    buildingData.j            = b.getCol();
                    buildingData.Level        = b.getCurrentLevel();
                    buildingData.SpecialSlot1 = (int)b.getRiceUnprepared();
                    buildingData.SpecialSlot2 = (int)b.getRicePrepared();
                }
                break;

                case BUILDINGS.ERA: {
                    Building_Era b = (Building_Era)getBuilding(builded.Key);
                    buildingData.i            = b.getRow();
                    buildingData.j            = b.getCol();
                    buildingData.Level        = b.getCurrentLevel();
                    buildingData.SpecialSlot1 = (int)b.getRiceUnprepared();
                    buildingData.SpecialSlot2 = (int)b.getRicePrepared();
                }
                break;

                case BUILDINGS.SILO: {
                    Building_Silo b = (Building_Silo)getBuilding(builded.Key);
                    buildingData.i            = b.getRow();
                    buildingData.j            = b.getCol();
                    buildingData.Level        = b.getCurrentLevel();
                    buildingData.SpecialSlot1 = (int)b.getAllTheRice();
                }
                break;

                case BUILDINGS.PLANTA: {
                    Building_Planta b = (Building_Planta)getBuilding(builded.Key);
                    buildingData.i            = b.getRow();
                    buildingData.j            = b.getCol();
                    buildingData.Level        = b.getCurrentLevel();
                    buildingData.SpecialSlot1 = (int)b.getRiceUnprepared();
                }
                break;
                }
                buildingManagerData.BuildingsBuilded.Add(buildingData);
            }
        }
    }