/// <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> public void Eat(F food) { _stoped = false; _lock.Read(() => { if (!CanWorking()) { return; } if (!_foods.TryAdd(food)) { return; } _enzyme.AllowOne(); }); }