Ejemplo n.º 1
0
    public void BuildUnits(int count)
    {
        Debug.Log("Build units " + count);

        if (count < 0)
        {
            Debug.Log("Number is low");
            return;
        }

        // 1 unit = 5 gold
        if (count * 5 > this.GoldCount)
        {
            Debug.Log("Not enough gold");
            return;
        }

        this.GoldCount -= count * 5;

        AudioPlayer.Instance.PlayTraining();

        if (this.UnitsBuildJob == null)
        {
            this.UnitsBuildJob = new UnitsBuildJob()
            {
                UnitsLeftToBuild = 0, UnitsPerBlockBuildTime = this.barracks.UnitsProductionSpeedPerBlock[this.BarracksLevel]
            }
        }
        ;

        this.UnitsBuildJob.UnitsLeftToBuild += count;

        Object.FindObjectOfType <GameManager>().Commitments.CommitUnitsTrainAction((ushort)count);
    }
Ejemplo n.º 2
0
    /// <remarks>No reorgs expected.</remarks>
    public void UpdateState(int newBlockNumber)
    {
        int blocksPassed = newBlockNumber - this.CurrentBlockNumber;

        if (blocksPassed <= 0)
        {
            return;
        }

        int oldBlockNumber = this.CurrentBlockNumber;

        this.CurrentBlockNumber = newBlockNumber;

        var goldMineWasUpgraded       = false;
        var goldMineUpgradedBlocksAgo = 0;

        // Upgrades.
        if (this.CurrentUpgradeJob != null && this.CurrentBlockNumber >= this.CurrentUpgradeJob.UpgradeFinishesByBlock)
        {
            // Upgrade level.
            if (this.CurrentUpgradeJob.BuildingType == BuildingType.Barracks)
            {
                this.BarracksLevel = this.CurrentUpgradeJob.LevelAfterUpgrade;
            }
            else
            {
                this.GoldMineLevel        = this.CurrentUpgradeJob.LevelAfterUpgrade;
                goldMineWasUpgraded       = true;
                goldMineUpgradedBlocksAgo = newBlockNumber - oldBlockNumber;
            }

            this.CurrentUpgradeJob = null;
        }

        // Update gold.
        if (!goldMineWasUpgraded)
        {
            int goldMined = blocksPassed * this.goldMine.GoldProductionSpeedPerBlock[this.GoldMineLevel];
            this.GoldCount += goldMined;
        }
        else
        {
            int goldMined = (blocksPassed - goldMineUpgradedBlocksAgo) * this.goldMine.GoldProductionSpeedPerBlock[this.GoldMineLevel - 1];
            goldMined += goldMineUpgradedBlocksAgo * this.goldMine.GoldProductionSpeedPerBlock[this.GoldMineLevel];

            this.GoldCount += goldMined;
        }

        // Update units.
        if (this.UnitsBuildJob != null)
        {
            int maxCreated = this.UnitsBuildJob.UnitsPerBlockBuildTime * blocksPassed;

            if (maxCreated >= this.UnitsBuildJob.UnitsLeftToBuild)
            {
                int unitsBuilt = this.UnitsBuildJob.UnitsLeftToBuild;
                this.UnitsBuildJob = null;

                this.UnitsCount += unitsBuilt;
            }
            else
            {
                this.UnitsBuildJob.UnitsLeftToBuild -= maxCreated;
                this.UnitsCount += maxCreated;
            }
        }
    }