Ejemplo n.º 1
0
    protected IEnumerator Construct()
    {
        constructing = true;
        spriteParent.gameObject.SetActive(false);
        player.capital.constructionList.Add(this);
        float HPincrease = (healthArray[1] - healthArray[0]) / maxConstructionTime;

        if (HPincrease > 0f)
        {
            ConstructionPS constructPS = ((GameObject)Instantiate(GameManager.GetGameObject("ConstructionPS"), transform.position, Quaternion.identity)).GetComponent <ConstructionPS> ();
            constructPS.Initiate(this);
            float constructionTime = 0f;
            while (constructionTime < maxConstructionTime && constructing && isAlive)
            {
                float constructTimeStep = player.capital.ConstructionOrRepairTimeStep(0);
                constructionTime += constructTimeStep;
                healthArray[0]   += HPincrease * constructTimeStep;
                if (healthBar)
                {
                    healthBar.ChangeHP(healthArray[0]);
                }
                yield return(null);
            }
        }
        if (isAlive)
        {
            FinishConstruction();
        }
    }
    private static IEnumerator RevertCoroutine(StrategicPoint stratPoint)
    {
        ConstructionPS conPS = ((GameObject)Instantiate(GameManager.GetGameObject("ConstructionPS"), stratPoint.transform.position, Quaternion.identity)).GetComponent <ConstructionPS> ();

        conPS.forceEmit = true;
        conPS.Initiate(stratPoint);
        yield return(new WaitForSeconds(revertWaitTime));

        stratPoint.Revert();
        conPS.forceEmit = false;
    }
Ejemplo n.º 3
0
    private IEnumerator Repair()
    {
        if (GameManager.HumanPlayer.GetResource(ResourceType.Wood) > 0)
        {
            repairing = true;
            player.capital.constructionList.Add(this);
            ConstructionPS constructPS = ((GameObject)Instantiate(GameManager.GetGameObject("ConstructionPS"), transform.position, Quaternion.identity)).GetComponent <ConstructionPS> ();
            constructPS.Initiate(this);
            while (healthArray[0] < healthArray[1] && healthArray[0] > 0 && repairing && isAlive)
            {
                if (GameManager.HumanPlayer.GetResource(ResourceType.Wood) <= 0)
                {
                    GameManager.HumanPlayer.ChangeResource(ResourceType.Wood, 0 - GameManager.HumanPlayer.GetResource(ResourceType.Wood));
                    repairing = false;
                    break;
                }
//				else if (player.capital.GetCurrentUnits() < 1 && constructPS.activeSelf) constructPS.SetActive(false);
//				else if (player.capital.GetCurrentUnits() >= 1 && !constructPS.activeSelf) constructPS.SetActive(true);
                float repairAmount = player.capital.ConstructionOrRepairTimeStep(1);
                healthArray[0] += repairAmount;
                GameManager.HumanPlayer.ChangeResource(ResourceType.Wood, -repairAmount);
                if (healthBar)
                {
                    healthBar.ChangeHP(healthArray[0]);
                }
                yield return(null);
            }
            repairing = false;
            if (healthArray[0] > healthArray[1])
            {
                healthArray[0] = healthArray[1];
                healthBar.ChangeHP(healthArray[0]);
            }
            if (!selected)
            {
                healthBar.gameObject.SetActive(false);
            }
            player.capital.constructionList.Remove(this);
        }
        else
        {
            yield return(null);
        }
    }