// 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);
        }
    }
示例#2
0
    private void RemovePowerConsumer()
    {
        IPowerRelated powerConsumer = powerGrid.FirstOrDefault(powerRelated => powerRelated.IsPowerConsumer);

        if (powerConsumer == null)
        {
            return;
        }

        RemoveFromPowerGrid(powerConsumer);
    }
示例#3
0
    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);
    }
示例#4
0
 public bool RequestPower(IPowerRelated powerRelated)
 {
     return(powerGrid.Contains(powerRelated));
 }
示例#5
0
 public void RemoveFromPowerGrid(IPowerRelated powerRelated)
 {
     powerGrid.Remove(powerRelated);
     AdjustPowelLevel();
 }
示例#6
0
 private void OnPowerValueChanged(IPowerRelated powerRelated)
 {
     RemoveFromPowerGrid(powerRelated);
     AddToPowerGrid(powerRelated);
 }