public override void interact(Player player) { // player interacts with machine to drop resources // can't remove more than the player has int wood_to_remove = player.CurrentWood; int stone_to_remove = player.CurrentStone; // remove resources from the player player.CurrentWood -= wood_to_remove; player.CurrentStone -= stone_to_remove; if (_currentDemand == null) { // no demand at the moment _uiManager.ShowMessage("The Machine seems satiated ... for now ..."); } else { // and remove from the current demand _currentDemand.Wood -= wood_to_remove; _currentDemand.Stone -= stone_to_remove; if (CheckDemandMet()) { // demand has been met _uiManager.ShowMessage("The Machine's demands have been met, temporarily"); _uiManager.HideMachineDemand(); _currentDemand = null; } else { // demand still not fulfilled _uiManager.UpdateCarryMessage(player); _uiManager.SetMachineDemandText(_currentDemand.ToString()); } } // satiate the machine machineSatiation += (wood_to_remove * _woodSatiationMultiplier) + (stone_to_remove * _stoneSatiationMultiplier); // update UI elements _uiManager.UpdateCarryMessage(player); }
private void Update() { if (_exploded) { return; } machineSatiation -= _satiationDegradationRate * Time.deltaTime; _uiManager.UpdateNeedle(machineSatiation); if (machineSatiation < DANGER_ZONE_BELOW && !_warningGiven) { _uiManager.ShowMessage("The machine is in danger of exploding!"); _warningGiven = true; } else if (machineSatiation > SLEEP_ZONE_ABOVE && !_warningGiven) { _uiManager.ShowMessage("The machine may go to sleep"); _warningGiven = true; } else if (machineSatiation >= DANGER_ZONE_BELOW && machineSatiation <= SLEEP_ZONE_ABOVE) { // clear the warning flag so that future warnings can be given _warningGiven = false; } if (_currentDemand == null) { timeTillNextDemand -= Time.deltaTime; if (timeTillNextDemand <= 0) { _currentDemand = Demand.GenerateDemand(); _uiManager.SetMachineDemandText(_currentDemand.ToString()); timeTillNextDemand = Random.Range(MIN_DEMAND_DELAY, MAX_DEMAND_DELAY); } } }