Beispiel #1
0
    public bool CanTrain(int amountToTrain)
    {
        bool hasEnoughResources = false;
        List <ResourceAmount> resourceAmounts = new List <ResourceAmount>();

        for (int i = 0; i < resourceCosts.Count; i++)
        {
            ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType);
            ResourceAmount cost          = resourceCosts[i];
            if (currentAmount.resourceAmount >= (cost.resourceAmount * amountToTrain))
            {
                resourceAmounts.Add(currentAmount);
            }
        }
        if (resourceAmounts.Count >= resourceCosts.Count)
        {
            hasEnoughResources = true;
            // resourceAmounts has the same order as resourceCosts
            for (int i = 0; i < resourceCosts.Count; i++)
            {
                resourceAmounts[i].resourceAmount -= (resourceCosts[i].resourceAmount * amountToTrain);
            }
            availabilityState = Troop.AvailabilityState.Training;
            GameEvents.TrainingStarted(this);
            GameEvents.OnTimePassed += CheckTrainingTime;
        }
        return(hasEnoughResources);
    }
Beispiel #2
0
    public bool StartResearching()
    {
        bool hasEnoughResources = false;
        List <ResourceAmount> resourceAmounts = new List <ResourceAmount>();

        for (int i = 0; i < resourceCosts.Count; i++)
        {
            ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType);
            ResourceAmount cost          = resourceCosts[i];
            if (currentAmount.resourceAmount >= cost.resourceAmount)
            {
                resourceAmounts.Add(currentAmount);
            }
        }
        if (resourceAmounts.Count >= resourceCosts.Count)
        {
            hasEnoughResources = true;
            // resourceAmounts has the same order as resourceCosts
            for (int i = 0; i < resourceCosts.Count; i++)
            {
                resourceAmounts[i].resourceAmount -= resourceCosts[i].resourceAmount;
            }
            availabilityState = AvailabilityState.Researching;
            GameEvents.TechResearchStarted(this);
            //GameEvents.OnTurnPassed += NewTurn;
            GameEvents.OnTimePassed += CheckTime;
        }
        return(hasEnoughResources);
    }
Beispiel #3
0
 public void TechUnlock()
 {
     availabilityState = AvailabilityState.Unlocked;
     GameEvents.TechUnlocked(this);
     GameEvents.OnTechResearchCompleted -= CheckRequirements;
     Debug.Log("Tech unlocked " + this.techName);
 }
Beispiel #4
0
 public void TroopUnlock()
 {
     availabilityState = AvailabilityState.Unlocked;
     GameEvents.TroopUnlocked(this);
     GameEvents.OnBuildingCompleted -= CheckTrainingRequirements;
     Debug.Log("Troop unlocked " + troopName);
 }
Beispiel #5
0
 public void HuntUnlock()
 {
     availabilityState = AvailabilityState.Unlocked;
     GameEvents.HuntUnlocked(this);
     GameEvents.OnTechResearchCompleted -= CheckHuntRequirements;
     Debug.Log("Hunt unlocked " + huntName);
 }
Beispiel #6
0
    public void Train()
    {
        GameEvents.TrainingCompleted(this);
        GameEvents.OnTimePassed -= CheckTrainingTime;

        availabilityState = AvailabilityState.Unlocked;
        Debug.Log("Troops were trained " + troopName);
    }
Beispiel #7
0
    public void Learn()
    {
        GameEvents.TechResearchCompleted(this);
        GameEvents.OnTimePassed -= CheckTime;

        availabilityState = AvailabilityState.Learned;
        Debug.Log("Tech was learned " + this.techName);
        //GameEvents.OnTurnPassed -= NewTurn;
    }
Beispiel #8
0
    public void HuntComplete()
    {
        GameEvents.HuntCompleted(this);
        GameEvents.HuntQuestCompleted(huntName);
        GameEvents.OnTimePassed -= CheckHuntingTime;

        availabilityState = AvailabilityState.Completed;
        Debug.Log(string.Format("Hunt was finished {0}", huntName));
    }
Beispiel #9
0
    public bool CanHunt()
    {
        bool canHunt = false;

        switch (requiredTroopType)
        {
        case Troop.TroopType.Infantry:
            if (MilitaryManager.Instance.infantryAmount >= neededArmyAmount)
            {
                canHunt = true;
            }
            break;

        case Troop.TroopType.Cavalry:
            if (MilitaryManager.Instance.cavalryAmount >= neededArmyAmount)
            {
                canHunt = true;
            }
            break;

        case Troop.TroopType.Spear:
            if (MilitaryManager.Instance.spearAmount >= neededArmyAmount)
            {
                canHunt = true;
            }
            break;

        case Troop.TroopType.Archer:
            if (MilitaryManager.Instance.archerAmount >= neededArmyAmount)
            {
                canHunt = true;
            }
            break;

        case Troop.TroopType.Magic:
            if (MilitaryManager.Instance.mageAmount >= neededArmyAmount)
            {
                canHunt = true;
            }
            break;

        default:
            break;
        }

        availabilityState        = AvailabilityState.Hunting;
        GameEvents.OnTimePassed += CheckHuntingTime;
        return(canHunt);
    }