Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (selecting)
        {
            lineR.enabled = true;
            myStorage     = null;
            LineFollowMouse();
            buildingUI.currentlyBuilding = true;
            if (Input.GetMouseButtonUp(0))
            {
                SetStorageAndPump();
            }
        }



        if (canPump && !starvedMode)
        {
            StartCoroutine(WaitToPump());
        }

        if (!selecting && myStorage == null)
        {
            lineR.enabled = false;
            canPump       = false;
            Debug.Log("Need STORAGE!");
        }
        else if (!selecting && myStorage != null)
        {
            if (!statsInitialized)
            {
                playerResources.CalculateWaterProduction(waterPumped, pumpRate, false);
                statsInitialized = true;
            }
        }
    }
    /// <summary>
    /// Swaps the type of the tile.
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <param name="newType">New type.</param>
    public void SwapTileType(int x, int y, TileData.Types newType)
    {
        // MAKE SURE THIS IS NOT A SPAWNED TILE ALREADY!!!
        // So we don't change the grid tile data where we don't want to!
        if (spawnedTiles [x, y] == null)
        {
            // swap the old type to new type
            switch (newType)
            {
            case TileData.Types.extractor:
                tiles [x, y] = new TileData("Extractor", newType, 0, 10000, 5, 5, 0, 0, extractorCost[1], extractorCost[0]);
                break;

            case TileData.Types.machine_gun:
                tiles [x, y] = new TileData("Machine Gun", newType, 0, 10000, 30, 5, 5, 0, machineGunCost[1], machineGunCost[0]);
                break;

            case TileData.Types.cannons:
                tiles [x, y] = new TileData("Cannons", newType, 0, 10000, 30, 5, 3, 0, seaWitchCost[1], seaWitchCost[0]);
                break;

            case TileData.Types.harpoonHall:
                tiles [x, y] = new TileData("Harpooner's Hall", newType, 0, 10000, 50, 6, 0, 0, harpoonHCost[1], harpoonHCost[0]);
                break;

            case TileData.Types.farm_s:
                tiles [x, y] = new TileData("Seaweed Farm", newType, 0, 10000, 25, 1, 0, 0, sFarmCost[1], sFarmCost[0]);
                break;

            case TileData.Types.storage:
                tiles [x, y] = new TileData("Storage", newType, 0, 10000, 35, 2, 0, 0, storageCost[1], storageCost[0]);
                break;

            case TileData.Types.desalt_s:
                tiles [x, y] = new TileData("Desalination Pump", newType, 0, 10000, 15, 1, 0, 0, sDesaltCost[1], sDesaltCost[0]);
                break;

            case TileData.Types.sniper:
                tiles [x, y] = new TileData("Sniper Gun", newType, 0, 10000, 0, 0, 0, 0, sniperCost[1], sniperCost[0]);
                break;

            case TileData.Types.seaWitch:
                tiles [x, y] = new TileData("Sea-Witch Crag", newType, 0, 10000, 0, 0, 0, 0, seaWitchCost[1], seaWitchCost[0]);
                break;

            case TileData.Types.nutrient:
                tiles [x, y] = new TileData("Nutrient Generator", newType, 0, 10000, 0, 0, 0, 0, nutriCost[1], nutriCost[0]);
                break;

            case TileData.Types.building:
                tiles [x, y] = new TileData(newType, 0, 10000);
                break;

            default:
                print("No tile changed.");
                break;
            }
            // Discover the tile to display it
            DiscoverTile(x, y, true);
            // if tile is a Building with a FOOD COST, apply it to resources
            if (tiles[x, y].foodCost > 0)
            {
                playerResources.totalFoodCost = playerResources.totalFoodCost + tiles[x, y].foodCost;
            }
        }
        else
        {
            // if we are swappin an already spawned tile we are MOST LIKELY turning it into an empty tile
            // BUT if this was any building that has a food cost that must be reflected in Player resources
            //	by subtracting from the total food cost
            if (tiles[x, y].foodCost > 0)
            {
                playerResources.totalFoodCost = playerResources.totalFoodCost - tiles[x, y].foodCost;
            }

            // ALSO if it's a Farm we need to subtract its FOOD production and its WATER consumed
            if (playerResources.foodProducedPerDay > 0)
            {
                if (tiles[x, y].tileType == TileData.Types.farm_s || tiles[x, y].tileType == TileData.Types.nutrient)
                {
                    FoodProduction_Manager foodM = spawnedTiles [x, y].GetComponent <FoodProduction_Manager>();
                    playerResources.CalculateFoodProduction(foodM.foodProduced, foodM.productionRate, foodM.waterConsumed, true);
                }
            }

            // AND if it's a STORAGE we need to subtract all the ORE and WATER from the resources
            if (tiles[x, y].tileType == TileData.Types.storage)
            {
                Storage storage = spawnedTiles[x, y].GetComponent <Storage>();
//				if (storage.oreStored > 0 || storage.waterStored > 0){
//					playerResources.ChangeResource("Ore", - storage.oreStored);
//					playerResources.ChangeResource("Water", -storage.waterStored);
//				}
                // remove the storage building from the list
                playerResources.RemoveStorageBuilding(storage);
            }

            // If it's an EXTRACTOR also need to subtract from Ore Produced
            if (tiles[x, y].tileType == TileData.Types.extractor)
            {
                Extractor extra = spawnedTiles [x, y].GetComponent <Extractor>();
                playerResources.CalculateOreProduction(extra.extractAmmnt, extra.extractRate, true);
            }

            // Same thing for a WATER PUMP
            if (tiles[x, y].tileType == TileData.Types.desalt_s || tiles[x, y].tileType == TileData.Types.desalt_m ||
                tiles[x, y].tileType == TileData.Types.desalt_l)
            {
                DeSalt_Plant pump = spawnedTiles [x, y].GetComponent <DeSalt_Plant>();
                playerResources.CalculateWaterProduction(pump.waterPumped, pump.pumpRate, true);
            }

            // RETURN 30% OF THE ORE COST TO THE RESOURCES
            float calc = (float)tiles[x, y].oreCost * 0.3f;
            playerResources.ore = playerResources.ore + (int)calc;

            Destroy(spawnedTiles[x, y].gameObject);
            tiles[x, y] = new TileData(newType, 0, 1);
        }
    }