Ejemplo n.º 1
0
    public void ExecuteActionOnBuilding(Vector3Int position, BuildingAction action)
    {
        GameObject        buildingLogic = _positionToBuildingLogic[position];
        BuildingHealth    health        = buildingLogic.GetComponent <BuildingHealth>();
        BuildingLogicBase logic         = buildingLogic.GetComponent <BuildingLogicBase>();

        switch (action)
        {
        case BuildingAction.UPGRADE_HEALTH:
            int healthUpgradeCost = GetHealthUpgradeCost(health);
            if (healthUpgradeCost > playerStats.GetMind())
            {
                Debug.Log("Upgrade health failed");
                return;
            }
            health.DoUpgradeHealth();
            playerStats.UpdateMind(-healthUpgradeCost);

            ConstructionSpace space = _positionToConstructionSpace[position];
            if (health.WallSprite != null && !_constructionSpaceToWallSprite.ContainsKey(space))
            {
                GameObject wallSprite = Instantiate(WallPrefab);
                wallSprite.GetComponent <SpriteRenderer>().sprite = health.WallSprite;
                wallSprite.transform.position         = GetConstructionSpaceWorldCenter(space) + Vector3.back;
                _constructionSpaceToWallSprite[space] = wallSprite;
            }

            switch (logic.GetBuildingType())
            {
            case "library":
                audioManager.PlayUpLibrary();
                break;

            case "market":
                audioManager.PlayUpMarket();
                break;

            case "gym":
                audioManager.PlayUpGym();
                break;

            case "amp":
                audioManager.PlayUpAmp();
                break;

            case "vice":
                audioManager.PlayUpVice();
                break;
            }
            return;

        case BuildingAction.UPGRADE_PRODUCTION:
            int productionUpgradeCost = GetProductionUpgradeCost(logic);
            if (productionUpgradeCost > playerStats.GetMind())
            {
                Debug.Log("Upgrade production failed");
                return;
            }
            logic.DoUpgradeProduction();
            playerStats.UpdateMind(-productionUpgradeCost);
            switch (logic.GetBuildingType())
            {
            case "library":
                audioManager.PlayUpLibrary();
                break;

            case "market":
                audioManager.PlayUpMarket();
                break;

            case "gym":
                audioManager.PlayUpGym();
                break;

            case "amp":
                audioManager.PlayUpAmp();
                break;

            case "vice":
                audioManager.PlayUpVice();
                break;
            }
            return;

        case BuildingAction.REPAIR:
            audioManager.PlayBuildingBuilt();
            int repairCost = GetRepairCost(health);
            if (repairCost > playerStats.GetMind())
            {
                Debug.Log("Repair failed");
                return;
            }
            health.DoRepair();
            playerStats.UpdateMind(-repairCost);
            return;
        }
    }