/// <summary> /// 分解食物,得到养分 /// </summary> private void Breakdown() { _lock.Read(() => { if (!CanWorking()) { return; } _foods.Using((food) => { bool success = false; if (_howBreakDowns != null) { bool breakSuccess = false; var nutrients = _howBreakDowns(food, out breakSuccess); if (breakSuccess) { foreach (var nutrient in nutrients) { if (_nutrients.TryAdd(nutrient)) { success = true; } } } } else if (_howBreakDown != null) { bool breakSuccess = false; var nutrient = _howBreakDown(food, out breakSuccess); if (breakSuccess) { if (_nutrients.TryAdd(nutrient)) { success = true; } } } if (success) { NutrientsInputted(); _stomach.AllowOne(); } }); }); }
/// <summary> /// 消化食物 /// </summary> private void Digest() { _lock.Read(() => { if (!CanWorking()) { return; } bool exist = true; while (exist) { exist = _nutrients.Using((nutrient) => { OutputNutrient(nutrient); }); } }); }