public void ModifyResource(ResourceType resource, int amount)
        {
            if (!_resources.ContainsKey(resource))
            {
                _resources.Add(resource, 0);
            }
            _resources[resource] += amount;

            OnResourcesUpdated?.Invoke(resource, _resources[resource]);
        }
Beispiel #2
0
    private void Awake()
    {
        mainCamera = Camera.main;

        population = new Population(0, Settings.DefaultPopulation);

        resources = new Resources(
            Settings.DefaultResources.Wood,
            Settings.DefaultResources.Food,
            Settings.DefaultResources.Stone,
            Settings.DefaultResources.Metal
            );

        OnResourcesUpdated  += userInterfaceController.GetOnResourcesUpdatedAction();
        OnPopulationUpdated += userInterfaceController.GetOnPopulationUpdatedAction();

        playerController.OnSelected   += userInterfaceController.GetOnSelectedAction();
        playerController.OnDeselected += userInterfaceController.GetOnDeselectedAction();

        playerController.OnStructuresSelected   += userInterfaceController.OnStructuresSelected;
        playerController.OnStructuresDeselected += userInterfaceController.OnStructuresDeselected;

        units = new List <Unit>();

        structures = new List <Structure>();
        foreach (var structure in unregisteredStructures)
        {
            structures.Add(structure);
            structure.Initialize(this, this);

            if (structure is IUnitRecruiter)
            {
                (structure as IUnitRecruiter).OnUnitRecruited += OnUnitRecruited;
            }

            population.allowed += structure.Properties.housing;
        }

        harvestables = new List <ISelectable>();
        foreach (var harvestable in GameObject.FindGameObjectsWithTag(Settings.Tags.Harvestable))
        {
            harvestables.Add(harvestable.GetComponent <ISelectable>());
        }

        playerController.SetGetSelectablesCall(GetSelectablesInBounds);

        OnResourcesUpdated?.Invoke(resources);
        OnPopulationUpdated?.Invoke(population);

        fogOfWarManager = Camera.main.GetComponent <IFogOfWarManager>();

        fogOfWarManager.AddLightObjects(structures.Select(structure => structure as ILighter));
        fogOfWarManager.AddLightObjects(units.Select(unit => unit as ILighter));
    }
Beispiel #3
0
    public bool TryPay(Resources price)
    {
        if (resources >= price)
        {
            resources.Subtract(price);
            OnResourcesUpdated?.Invoke(resources);
            return(true);
        }

        return(false);
    }
Beispiel #4
0
 private void HandleTowerOnSpawn(Tower tower)
 {
     myTowers.Add(tower);
     OnResourcesUpdated?.Invoke(_resources);
 }
Beispiel #5
0
 private void HandleEnemyOnDespawn(Enemy enemy)
 {
     _score     += 1;
     _resources += enemy.GetEnemyResourceValue;
     OnResourcesUpdated?.Invoke(_resources);
 }
Beispiel #6
0
 public void Deliver(ResourceType resourceType, int amount)
 {
     resources.AddAmount(resourceType, amount);
     OnResourcesUpdated?.Invoke(resources);
 }
Beispiel #7
0
 public void Refund(Resources resources)
 {
     this.resources.Add(resources);
     OnResourcesUpdated?.Invoke(this.resources);
 }