public void ModifyResource(ResourceType resource, int amount) { if (!_resources.ContainsKey(resource)) { _resources.Add(resource, 0); } _resources[resource] += amount; OnResourcesUpdated?.Invoke(resource, _resources[resource]); }
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)); }
public bool TryPay(Resources price) { if (resources >= price) { resources.Subtract(price); OnResourcesUpdated?.Invoke(resources); return(true); } return(false); }
private void HandleTowerOnSpawn(Tower tower) { myTowers.Add(tower); OnResourcesUpdated?.Invoke(_resources); }
private void HandleEnemyOnDespawn(Enemy enemy) { _score += 1; _resources += enemy.GetEnemyResourceValue; OnResourcesUpdated?.Invoke(_resources); }
public void Deliver(ResourceType resourceType, int amount) { resources.AddAmount(resourceType, amount); OnResourcesUpdated?.Invoke(resources); }
public void Refund(Resources resources) { this.resources.Add(resources); OnResourcesUpdated?.Invoke(this.resources); }