Ejemplo n.º 1
0
    bool haveEnoughResources(int num)
    {
        BuildingCost cost = BuildingRequirements [num];

        if (GameManager.instance.WoodAmount >= cost.Wood &&
            GameManager.instance.StoneAmount >= cost.Stone &&
            GameManager.instance.GoldAmount >= cost.Gold)
        {
            return(true);
        }

        if (GameManager.instance.WoodAmount < cost.Wood && cost.Wood != 0)
        {
            UIManager.instance.FlashResourceText(Color.red, Resource.ResourceType.Wood);
        }
        if (GameManager.instance.StoneAmount < cost.Stone && cost.Stone != 0)
        {
            UIManager.instance.FlashResourceText(Color.red, Resource.ResourceType.Stone);
        }
        if (GameManager.instance.GoldAmount < cost.Gold && cost.Gold != 0)
        {
            UIManager.instance.FlashResourceText(Color.red, Resource.ResourceType.Gold);
        }

        return(false);
    }
Ejemplo n.º 2
0
    public void BuildingCostTooltip(GameObject objectRef)
    {
        tooltip1.enabled = true;
        tooltip2.enabled = true;
        tooltip3.enabled = true;
        tooltip4.enabled = true;


        if (moneyRef.availableResources > objectRef.GetComponent <BuildingCost>())
        {
            tooltip5.SetActive(false);
        }
        else
        {
            tooltip5.SetActive(true);
        }

        BuildingCost bPrice = objectRef.GetComponent <BuildingCost>();

        tooltip1.text = "Gold price: " + bPrice.moneyCost;
        tooltip2.text = "Wood Cost: " + bPrice.woodCost;
        tooltip3.text = "Stone Cost: " + bPrice.stoneCost;
        tooltip4.text = "Iron Cost: " + bPrice.ironCost;
        return;
    }
Ejemplo n.º 3
0
    /// <summary> Decrement BuildingCost from Inventory, otherwise return GoodsCollection of missing goods </summary>
    public virtual GoodsCollection TryStartConstruction(GoodsCollection inventory)
    {
        var missingGoods = new GoodsCollection();

        //check required materials
        foreach (Good good in BuildingCost.Keys)
        {
            var foo = inventory[good] - BuildingCost[good];
            if (foo < 0)
            {
                missingGoods.Add(good, -foo);
            }
        }

        if (missingGoods.Count > 0)
        {
            return(missingGoods);
        }

        //+- goods
        foreach (Good good in inventory.Keys.ToArray())
        {
            if (BuildingCost.ContainsKey(good))
            {
                inventory[good] -= BuildingCost[good];
            }
        }

        return(missingGoods);
    }
Ejemplo n.º 4
0
 //debug/testing
 public void SpawnEnemy()
 {
     buildingCharge       = new BuildingCost();
     uiState              = "Building";
     mouseRef.BuildingRef = enemyRef;
     mouseRef.Build();
     MouseHandler.mouse.building = true;
 }
Ejemplo n.º 5
0
    public void StartPlacingBuilding(int index)
    {
        if (index < 0 || index >= Buildings.Length)
        {
            throw new ArgumentOutOfRangeException();
        }

        currentBuilding = Buildings[index];
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the building cost for specific level
        /// </summary>
        /// <param name="building"></param>
        /// <param name="level"></param>
        public static long[] GetBuildingCost(Classificator.BuildingEnum building, int level)
        {
            long[] ret      = new long[4];
            var    baseCost = BuildingCost.GetRow((int)building);

            for (int i = 0; i < 4; i++)
            {
                var cost = baseCost[i] * Math.Pow(baseCost[4], level - 1);
                ret[i] = (long)Math.Round(cost / 5.0) * 5;
            }
            return(ret);
        }
Ejemplo n.º 7
0
 public void BuildMedical()
 {
     if (MoneyManager.moneyManager.availableResources > b_Medical.GetComponent <BuildingCost>())
     {
         tooltipOn = false;
         uiState   = "Building";
         buildPanel.SetActive(false);
         mouseRef.BuildingRef = b_Medical;
         mouseRef.Build();
         buildingCharge = b_Medical.GetComponent <BuildingCost>();
         MouseHandler.mouse.building = true;
     }
 }
Ejemplo n.º 8
0
 public void BuildMarket()
 {
     if (MoneyManager.moneyManager.availableResources > b_market.GetComponent <BuildingCost>() && !marketBuilt)
     {
         marketBuilt = true;
         tooltipOn   = false;
         uiState     = "Building";
         buildPanel.SetActive(false);
         mouseRef.BuildingRef = b_market;
         mouseRef.Build();
         buildingCharge = b_market.GetComponent <BuildingCost>();
         MouseHandler.mouse.building = true;
     }
 }
Ejemplo n.º 9
0
    private void Update()
    {
        if (!TimeManager.Paused)
        {
            currentBuilding = null;
            return;
        }

        for (int i = 0; i <= 8; i++)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1 + i))
            {
                StartPlacingBuilding(i);
            }
        }

        PlaceBuilding();
    }
Ejemplo n.º 10
0
 protected override void OnAwake()
 {
     buildingCost = GetComponentInParent <HeirarchyNode>().GetComponentInChildren <BuildingCost>();
 }
Ejemplo n.º 11
0
 public bool Equals(BuildingCost other)
 {
     return(resourceType == other.resourceType && cost == other.cost);
 }
Ejemplo n.º 12
0
    private void PlaceBuilding()
    {
        if (currentBuilding == null)
        {
            return;
        }

        // Right click aborts
        if (Input.GetMouseButtonDown(1))
        {
            currentBuilding = null;
            return;
        }

        // Get the buildings position on the plane
        var(isValid, point, pos) = MousePosToBuildingCenter(currentBuilding.Building, Input.mousePosition);

        if (!isValid)
        {
            return;
        }

        // Draw the buildings grid
        bool buildingPlacementValid = true;

        for (int x = 0; x < currentBuilding.Building.Width; x++)
        {
            for (int y = 0; y < currentBuilding.Building.Length; y++)
            {
                var testPoint = new Point(point.X + x, point.Y + y);
                var testPos   = GameGrid.Instance.PointToPosition(testPoint);

                var isFree = GameGrid.Instance.GetTile(testPoint).IsBuildable;
                buildingPlacementValid &= isFree;

                // Ugly direct mode! :D
                var material = isFree ? ValidPlacementMaterial : InvalidPlacementMaterial;

                var scale = GameGrid.Instance.Scale;
                var mesh  = new Mesh
                {
                    vertices = new[]
                    {
                        testPos,
                        testPos + Vector3.forward * scale,
                        testPos + Vector3.right * scale + Vector3.forward * scale,
                        testPos + Vector3.right * scale,
                    },
                    triangles = new[]
                    {
                        0, 1, 2,
                        0, 2, 3
                    }
                };

                Graphics.DrawMesh(mesh, Matrix4x4.identity, material, 0);
            }
        }

        // Left click to build
        if (buildingPlacementValid && Input.GetMouseButtonDown(0))
        {
            // If there are enough resources, build the building, otherwise do nothing
            if (ResourceManager.TryTakeResources(currentBuilding.Costs))
            {
                Instantiate(currentBuilding.Building, pos, Quaternion.identity);
                currentBuilding = null;
            }
        }
    }
Ejemplo n.º 13
0
 public void Show(BuildingCost toShow)
 {
     this.m_amountText.text = $"{toShow.Cost}";
     this.m_icon.sprite     = toShow.Type.Icon;
 }