コード例 #1
0
ファイル: Purchasables.cs プロジェクト: elliottsmith1/GA-RTS
    public void CheckWealth(int _gold, int _wood, int _pop, int _maxPop)
    {
        if (_gold >= barracksGoldCost && _wood >= barracksWoodCost)
        {
            barracksButton.interactable = true;
        }
        else
        {
            barracksButton.interactable = false;
        }
        if (_gold >= archeryGoldCost && _wood >= archeryWoodCost)
        {
            archeryButton.interactable = true;
        }
        else
        {
            archeryButton.interactable = false;
        }
        if (_gold >= houseGoldCost && _wood >= houseWoodCost)
        {
            houseButton.interactable = true;
        }
        else
        {
            houseButton.interactable = false;
        }
        if (_gold >= lumberGoldCost && _wood >= lumberWoodCost)
        {
            lumberButton.interactable = true;
        }
        else
        {
            lumberButton.interactable = false;
        }
        if (_gold >= marketGoldCost && _wood >= marketWoodCost)
        {
            marketButton.interactable = true;
        }
        else
        {
            marketButton.interactable = false;
        }
        if (_gold >= blacksmithGoldCost && _wood >= blacksmithWoodCost)
        {
            blacksmithButton.interactable = true;
        }
        else
        {
            blacksmithButton.interactable = false;
        }

        if (_gold >= infantryGoldCost && infantryPopCost + _pop <= _maxPop)
        {
            infantryButton.interactable = true;
        }
        else
        {
            infantryButton.interactable = false;
        }
        if (_gold >= spearmanGoldCost && spearmanPopCost + _pop <= _maxPop && playerTechManager.GetTechLevel("weaponTech") > 1 && playerTechManager.GetTechLevel("armourTech") > 1)
        {
            spearmanButton.interactable = true;
        }
        else
        {
            spearmanButton.interactable = false;
        }
        if (_gold >= pikemanGoldCost && pikemanPopCost + _pop <= _maxPop && playerTechManager.GetTechLevel("weaponTech") > 2 && playerTechManager.GetTechLevel("armourTech") > 1)
        {
            pikemanButton.interactable = true;
        }
        else
        {
            pikemanButton.interactable = false;
        }
        if (_gold >= heavyInfantryGoldCost && heavyInfantryPopCost + _pop <= _maxPop && playerTechManager.GetTechLevel("weaponTech") > 2 && playerTechManager.GetTechLevel("armourTech") > 2)
        {
            heavyInfantryButton.interactable = true;
        }
        else
        {
            heavyInfantryButton.interactable = false;
        }

        if (_gold >= archerGoldCost && archerPopCost + _pop <= _maxPop)
        {
            archerButton.interactable = true;
        }
        else
        {
            archerButton.interactable = false;
        }
        if (_gold >= crossbowmanGoldCost && crossbowmanPopCost + _pop <= _maxPop && playerTechManager.GetTechLevel("rangedTech") > 1 && playerTechManager.GetTechLevel("armourTech") > 1)
        {
            crossbowmanButton.interactable = true;
        }
        else
        {
            crossbowmanButton.interactable = false;
        }

        CheckTechWealth(_gold, _wood);
    }
コード例 #2
0
ファイル: UnitManager.cs プロジェクト: elliottsmith1/GA-RTS
    public void SpawnUnit(string _unit)
    {
        if (buildingManager.GetActiveBuilding().GetSpawnQueue().Count < 6)
        {
            Vector3    pos    = buildingManager.GetActiveBuilding().GetUnitSpawnPos();
            GameObject prefab = infantryPrefab;

            switch (_unit)
            {
            case "infantry":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = infantryPrefab;
                break;

            case "archer":
                playerManager.AddGold(-purchasables.archerGoldCost);
                selectedUnitPopCost  = purchasables.archerPopCost;
                selectedUnitGoldCost = purchasables.archerGoldCost;
                prefab = archerPrefab;
                break;

            case "crossbowman":
                playerManager.AddGold(-purchasables.crossbowmanGoldCost);
                selectedUnitPopCost  = purchasables.crossbowmanPopCost;
                selectedUnitGoldCost = purchasables.crossbowmanGoldCost;
                prefab = crossbowmanPrefab;
                break;

            case "spearman":
                playerManager.AddGold(-purchasables.spearmanGoldCost);
                selectedUnitPopCost  = purchasables.spearmanPopCost;
                selectedUnitGoldCost = purchasables.spearmanGoldCost;
                prefab = spearmanPrefab;
                break;

            case "pikeman":
                playerManager.AddGold(-purchasables.pikemanGoldCost);
                selectedUnitPopCost  = purchasables.pikemanPopCost;
                selectedUnitGoldCost = purchasables.pikemanGoldCost;
                prefab = pikemanPrefab;
                break;

            case "mage":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = magePrefab;
                break;

            case "heavyinfantry":
                playerManager.AddGold(-purchasables.heavyInfantryGoldCost);
                selectedUnitPopCost  = purchasables.heavyInfantryPopCost;
                selectedUnitGoldCost = purchasables.heavyInfantryGoldCost;
                prefab = heavyInfantryPrefab;
                break;

            case "mountedinfantry":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = mountedInfantryPrefab;
                break;

            case "mountedarcher":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = mountedArcherPrefab;
                break;

            case "mountedmage":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = mountedMagePrefab;
                break;

            case "mountedspearman":
                playerManager.AddGold(-purchasables.infantryGoldCost);
                selectedUnitPopCost  = purchasables.infantryPopCost;
                selectedUnitGoldCost = purchasables.infantryGoldCost;
                prefab = mountedSpearmanPrefab;
                break;
            }

            if ((playerManager.GetPopulation() + selectedUnitPopCost) <= playerManager.GetPopulationLimit())
            {
                GameObject unit = Instantiate(prefab, pos, Quaternion.identity);
                playerManager.AddPopulation(selectedUnitPopCost);
                NewUnit(unit);
                unit.SetActive(false);
                Unit unitScript = unit.GetComponent <Unit>();
                unitScript.SetPopulationValue(selectedUnitPopCost);
                if (unitScript.GetMelee())
                {
                    unitScript.IncreaseDamage(techManager.GetTechLevel("meleeDamage") * techManager.GetBuffAmount());
                    unitScript.IncreaseArmour(techManager.GetTechLevel("meleeArmour") * techManager.GetBuffAmount());
                }
                else
                {
                    unitScript.IncreaseDamage(techManager.GetTechLevel("rangedDamage") * techManager.GetBuffAmount());
                    unitScript.IncreaseArmour(techManager.GetTechLevel("rangedArmour") * techManager.GetBuffAmount());
                }
                buildingManager.GetActiveBuilding().NewSpawnUnit(unit.GetComponent <Unit>(), selectedUnitGoldCost);
            }
        }
    }