public static void AddResources(this IResourceContainer container, IResourceCost resources) { foreach (var resource in resources.GetCost()) { container.ChangeResource(resource.Key, resource.Value); } }
private void Init() { _mods = new ModContainer(_stats, _events); Instance = this; _health = GetComponent <IHealthContainer>(); _unlocks = GetComponent <IUnlockList>(); _resources = GetComponent <IResourceContainer>(); _inventory = GetComponent <IInventory>(); if (_resources != null) { _resources?.ChangeResource(CreditsResource, 0); } ResourceEarningMultiplier = new Dictionary <string, IStatReference>(); _resourceFractionTrackers = new Dictionary <string, float>(); Resource[] resources = Content.GetAll <Resource>("*/Resources"); foreach (Resource resource in resources) { ResourceEarningMultiplier.Add(resource.Identifier, _stats.AddStat(GenerateStatInfo(resource), 1f)); _resourceFractionTrackers.Add(resource.Identifier, 0f); } OnNewPlayerInstance?.Invoke(this); }
private void Start() { IResourceContainer container = GetComponent <IResourceContainer>(); foreach (var resource in Resources.GetCost()) { container.ChangeResource(resource.Key, resource.Value); } Destroy(this); }
public static bool TrySpend(this IResourceContainer container, IResourceCost cost) { if (HasEnough(container, cost)) { foreach (var element in cost.GetCost()) { container.ChangeResource(element.Key, -element.Value); } return(true); } return(false); }