예제 #1
0
    public void UpdatePerDay()
    {
        m_graphBuildings.Foreach((UT_Node <BuildingStats> node) =>
        {
            node.GetData().overallMood      = 0;
            node.GetData().availability     = 0;
            node.GetData().createdInstances = 0;
        });

        List <IBuilding> buildings = M_BuildingManager.SGetBuildings();

        foreach (IBuilding building in buildings)
        {
            if (building is IBuildingHouse)
            {
                GetNode(building.GetData().id).GetData().createdInstances++;
                continue;
            }
            if (!(building is IBuildingProduction))
            {
                continue;
            }

            IBuildingProduction     prod = (IBuildingProduction)building;
            UT_Node <BuildingStats> node = GetNode(building.GetData().id);
            node.GetData().overallMood  += prod.GetMood();
            node.GetData().createdInstances++;

            if (prod.IsWorking())
            {
                M_WaresManager.SAddProductiveBuilding(prod.GetId(), prod.GetProducedWareType());
            }
            else
            {
                M_WaresManager.SRemoveProductiveBuilding(prod.GetId(), prod.GetProducedWareType());
            }
        }

        m_graphBuildings.Foreach((UT_Node <BuildingStats> node) =>
        {
            BuildingStats stats = node.GetData();
            foreach (DAT_Building.BuildDependency dep in stats.data.dependencies)
            {
                if (stats.overallMood > dep.requiredMood)
                {
                    UT_Node <BuildingStats> tempNode = GetNode(dep.unlocksBuilding);
                    tempNode.GetData().availability += 1;
                    if (tempNode.GetData().availability == tempNode.GetAdjacent().Count &&
                        m_currentBuildingsLevel < tempNode.GetData().buildingLevel)
                    {
                        m_currentBuildingsLevel = tempNode.GetData().buildingLevel;
                    }
                }
            }
        });
    }
예제 #2
0
파일: Settler.cs 프로젝트: Rivenort/Test
    public void UpdateFavoriteWares()
    {
        for (int i = 0; i < m_favoriteWares.Count; i++)
        {
            FavoriteWare fav = m_favoriteWares[i];
            bool         res = M_WaresManager.SIsWareProduced(fav.ware);

            if (res && !fav.active)
            {
                m_moodWares += fav.mood;
                fav.active   = true;
            }
            else if (!res && fav.active)
            {
                m_moodWares -= fav.mood;
                fav.active   = false;
            }
        }
    }
예제 #3
0
    /// <summary> Creates a new settler </summary>
    /// <returns>Guid of a new settler</returns>
    public Guid CreateSettler(Guid houseId)
    {
        Settler settler = new Settler(houseId);

        settler.SetName(GetRandName());
        settler.SetPortrait(GetRandPortrait());

        List <FavoriteBuilding> favoriteBuildings = new List <FavoriteBuilding>();
        List <FavoriteWare>     favoriteWares     = new List <FavoriteWare>();
        int FAVORITE_BUILDINGS = 3;
        int FAVORITE_WARES     = 3;

        M_BuildingManager.SEnableUniqueRandomizing(FAVORITE_BUILDINGS);
        for (int i = 0; i < FAVORITE_BUILDINGS; i++)
        {
            FavoriteBuilding temp = new FavoriteBuilding();
            temp.maxMood         = 20;
            temp.buildingTemplId = M_BuildingManager.SGetRandProductionBuildingTempl();
            temp.active          = false;
            favoriteBuildings.Add(temp);
        }


        M_WaresManager.SEnableUniqueWareRandomizing(FAVORITE_WARES);
        for (int i = 0; i < FAVORITE_WARES; i++)
        {
            FavoriteWare temp = new FavoriteWare();
            temp.mood   = UnityEngine.Random.Range(10, 21);;
            temp.ware   = M_WaresManager.SGetRandWare();
            temp.active = false;
            favoriteWares.Add(temp);
        }

        settler.SetFavoriteBuildings(favoriteBuildings);
        settler.SetFavortiteWares(favoriteWares);


        m_settlers.Add(settler);
        Debug.Log("CreateSettler id: " + settler.GetId());
        return(settler.GetId());
    }
예제 #4
0
    void Start()
    {
        Debug.Log("GameHelper -> Start()");
        s_instance = this;

        m_camController = Camera.main.GetComponent <CameraController>();
        if (m_camController == null)
        {
            Debug.LogWarning("Couldn't get CameraController from Camera.main!");
        }

        if (dayText == null || foodText == null || researchText == null)
        {
            Debug.LogWarning("One of the TMP_Text objects is not initialized.");
        }
        else
        {
            m_resourcesManager = M_InGameResourcesManager.GetInstance(foodText, dayText, researchText);
        }

        m_buildingManager = M_BuildingManager.Instance;
        m_mapManager      = M_MapManager.Instance;
        m_settlersManager = M_SettlersManager.Instance;
        m_inputManager    = M_InputManager.Instance;
        m_waresManager    = M_WaresManager.Instance;
        m_saveManager     = M_SaveManager.Instance;

        // Load level
        GameObject menuManager = GameObject.FindGameObjectWithTag("MenuManager");

        if (menuManager != null)
        {
            SceneLoader sceneLoader = menuManager.GetComponent <SceneLoader>();
            if (sceneLoader != null)
            {
                if (sceneLoader.gameData == null)
                {
                    LoadLevel(defaultGameData);
                }
                else
                {
                    LoadLevel(sceneLoader.gameData);
                }


                if (sceneLoader.saveId > 0)
                {
                    LoadSave(sceneLoader.saveId);
                }
            }
            else
            {
                Debug.LogWarning("Cannot find " + typeof(SceneLoader).Name + " component!");
            }
        }
        else
        { // Only if we started from Game scene, because MenuManager hasn't been initialized.
            if (defaultGameData != null)
            {
                Debug.LogWarning("Loading using default data .");
                LoadLevel(defaultGameData);
            }
            else
            {
                Debug.LogWarning("Couldn't find either MenuManager or default DAT_Game!");
            }
        }
        ResumeGame();
    }