// If this furniture generates power then powerValue will be positive, if it consumer power then it will be negative private void InvokePowerValueChanged(IPowerRelated powerRelated) { Action <IPowerRelated> handler = PowerValueChanged; if (handler != null) { handler(powerRelated); } }
private void RemovePowerConsumer() { IPowerRelated powerConsumer = powerGrid.FirstOrDefault(powerRelated => powerRelated.IsPowerConsumer); if (powerConsumer == null) { return; } RemoveFromPowerGrid(powerConsumer); }
public bool AddToPowerGrid(IPowerRelated powerRelated) { if (PowerLevel + powerRelated.PowerValue < 0) { return(false); } powerGrid.Add(powerRelated); AdjustPowelLevel(); powerRelated.PowerValueChanged += OnPowerValueChanged; Furniture furniture = powerRelated as Furniture; if (furniture != null) { furniture.cbOnRemoved += RemoveFromPowerGrid; } return(true); }
public bool RequestPower(IPowerRelated powerRelated) { return(powerGrid.Contains(powerRelated)); }
public void RemoveFromPowerGrid(IPowerRelated powerRelated) { powerGrid.Remove(powerRelated); AdjustPowelLevel(); }
private void OnPowerValueChanged(IPowerRelated powerRelated) { RemoveFromPowerGrid(powerRelated); AddToPowerGrid(powerRelated); }