示例#1
0
 bool CheckCosts()
 {
     if (stoneCost <= resourcesDataController.GetResourceAmount(STONE) && woodCost <= resourcesDataController.GetResourceAmount(WOOD)
         && mineralsCost <= resourcesDataController.GetResourceAmount(MINERALS) && godForceCost <= resourcesDataController.GetResourceAmount(GODFORCE)
         && foodCost <= resourcesDataController.GetResourceAmount(FOOD))
     {
         return true;
     }
     else
         return false;
 }
示例#2
0
    //Checks to see if there are enought resources to run the building
    void CheckUpkeep()
    {
        if (BuildingType.name == "BasicFarm")
        {
            Food food = GetComponent <Food>();

            if (food.FoodValue >= food.MaxFood)
            {
                UpkeepValid    = false;
                BuildingActive = false;
                return;
            }
        }

        //check Upkeep to see if building can work
        if (resourcesDataController.GetResourceAmount(GODFORCE) >= BuildingType.GodForceUpkeep &&
            resourcesDataController.GetResourceAmount(ENERGY) >= BuildingType.EnergyUpkeep &&
            resourcesDataController.GetResourceAmount(RESEARCH) >= BuildingType.ResearchUpkeep &&
            resourcesDataController.GetResourceAmount(FOOD) >= BuildingType.FoodUpkeep &&
            resourcesDataController.GetResourceAmount(WATER) >= BuildingType.WaterUpkeep &&
            resourcesDataController.GetResourceAmount(STONE) >= BuildingType.StoneUpkeep &&
            resourcesDataController.GetResourceAmount(WOOD) >= BuildingType.WoodUpkeep &&
            resourcesDataController.GetResourceAmount(MINERALS) >= BuildingType.MineralUpkeep)
        {
            UpdateUpkeep();

            UpkeepValid = true;

            if (UserOverrideBuildingActive)
            {
                BuildingActive = true;
            }
            else if (UserOverrideBuildingActive == false)
            {
                BuildingActive = false;
            }

            transform.GetChild(1).gameObject.GetComponent <SpriteRenderer>().color = WorkplaceColor;
        }

        //update Building Color & state
        else
        {
            UpkeepValid    = false;
            BuildingActive = false;
            transform.GetChild(1).gameObject.GetComponent <SpriteRenderer>().color = Color.red;
        }
    }
示例#3
0
    public void CreatingLand()
    {
        note.SetActive(true);

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // get the collision point of the ray with the z = 0 plane
        Vector3    worldPoint = ray.GetPoint(-ray.origin.z / ray.direction.z);
        Vector3Int position   = mapGrid.WorldToCell(worldPoint);

        hoverTile.transform.position = position + hoverTileOffset;

        _godForce = resourcesDataController.GetResourceAmount(GODFORCE);

        if (Input.GetMouseButton(0))
        {
            if (_godForce > LandCost && LandTileMap.GetTile(position) == null)     //create land on left click
            {
                LandTileMap.SetTile(position, LandTile);                           //remove water
                WaterTileMap.SetTile(position, null);                              // create land

                resourcesDataController.UpdateResourceAmount(GODFORCE, -LandCost); // update god force
                resourcesDataController.UpdateResourcesValue();

                //refresh colliders
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = false;
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = true;

                // update positions for pathfinder
                position.x += mapCreator.MapWidth / 2;
                position.y += mapCreator.MapHeight / 2;
                Utils.UpdatePathfinderNode(position, true);
            }
        }

        if (Input.GetMouseButton(1)) // remove land on right click
        {
            if (LandTileMap.GetTile(position) != null)
            {
                LandTileMap.SetTile(position, null);       //remove land
                WaterTileMap.SetTile(position, WaterTile); // return water

                //refresh colliders
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = false;
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = true;

                resourcesDataController.UpdateResourceAmount(GODFORCE, LandCost);;  // update god force
                resourcesDataController.UpdateResourcesValue();

                // update positions for pathfinder
                position.x += mapCreator.MapWidth / 2;
                position.y += mapCreator.MapHeight / 2;

                Utils.UpdatePathfinderNode(position, false);
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            note.SetActive(false);
            hoverTile.transform.position = new Vector3(0f, -20f, 0f);
            LevelManagerRef.StateMachineRef.ChangeState(LevelManagerRef.States[LevelManager.StatesEnum.BaseState]);
        }
    }