public bool AddMaximumAmount(RecourceType type, int amount, out int changed) { int freeSpace = GetFreeSpace(); // Debug.Log("free " + freeSpace + " amount " + amount); if (AcceptableTypes.Contains(RecourceType.all) || AcceptableTypes.Contains(type)) { if (freeSpace >= amount) { // Debug.Log("f>=a, changed for a"); changeRecource(type, amount); changed = amount; return(true); } else { // Debug.Log("f<a, changed for f"); changeRecource(type, freeSpace); changed = freeSpace; return(false); } } // Debug.Log("unacceptable type"); changed = 0; return(false); }
public bool SubstractMaximumAmount(RecourceType type, int amount, out int changed) { //убирает из склада максимальное количество //возвращает тру только если списано все количество ресурса //amount должен быть положительный! if (amount < 0) { Debug.Log("прилетел amount < 0, проверяй"); } int avaliable = GetAmount(type); if (avaliable == 0) { changed = 0; return(false); } if (avaliable >= amount) { changeRecource(type, -amount); changed = amount; return(true); } else { changeRecource(type, -avaliable); changed = avaliable; return(false); } }
public int GetAmount(RecourceType type) { if (Recources.ContainsKey(type)) { return(Recources[type]); } else { return(0); } }
private void Awake() { instance = this; InputHandler.CloseAllWindowsPressed += HideRecourceInfo; foreach (var item in Enum.GetValues(typeof(RecourceType))) { RecourceType rectype = (RecourceType)item; if (rectype == RecourceType.all) { continue; } var Image = Instantiate(recourceImagePrefab, layout); RecourceImage recImage = Image.GetComponent <RecourceImage>(); recImage.ChangeRecourceText("0"); recImage.ChangeRecorceImage(recourceIcons.Sprites[(int)rectype]); recourceImages.Add(rectype, recImage); } }
void changeRecource(RecourceType type, int amount) { if (amount == 0) { return; } if (Recources.ContainsKey(type)) { Recources[type] += amount; } else { Recources.Add(type, amount); } TotalAmountOfGoods += amount; RecourceChanged.Invoke(type, Recources[type], this); RecourcesChanged.Invoke(this); }
//запрос ресурса у конкретного склада void requestRecources(RecourceType type, int amount, Storage storage) { if (storage.SubstractMaximumAmount(type, amount, out int changed)) { RecourcesLeftToDeliver.Remove(type); RecourcesLeftChanged.Invoke(this); if (UtilityDebug.BuildingConstructionLog) { Debug.Log($"[State_Construction] {Building.BuildingName} получил вcе необходимые [{type}]" + $" со склада {storage.Building.BuildingName} [{Time.deltaTime}]", Building.gameObject); } } else if (changed >= 0) { RecourcesLeftToDeliver[type] -= changed; RecourcesLeftChanged.Invoke(this); if (UtilityDebug.BuildingConstructionLog) { Debug.Log($"[State_Construction] {Building.BuildingName} получил [{changed}] [{type}]" + $" со склада {storage.Building.BuildingName}, осталось [{RecourcesLeftToDeliver[type]}] [{Time.deltaTime}]", Building.gameObject); } } }
public void SubstractOutput(RecourceType type, int amount) { OutputRecourcesLocal[type] -= amount; OutputSubstracted.Invoke(); }
public Recource(RecourceType type, int amount) { Type = type; Amount = amount; }
public static void UpdateRecourceInfo(RecourceType type, int amount, Storage storage) { recourceImages[type].ChangeRecourceText(amount.ToString()); instance.totalStorageAmountText.text = "Заполненность склада: " + storage.TotalAmountOfGoods + "/" + storage.Capacity; }