public void ConnectOutlet(PowerOutlet outlet) { var mySink = GetComponentInParent <IPowerSink>(); var otherSource = outlet.GetComponent <IPowerSource>(); var mySource = GetComponentInParent <IPowerSource>(); var otherSink = outlet.GetComponent <IPowerSink>(); // I want to draw power from other /* Me(Sink) -----> Other(source)*/ if (mySink != null && otherSource != null) { _sink = mySink; _source = otherSource; } else // Other wants to draw power from me /* Me(Source) <----- Other(sink)*/ if (mySource != null && otherSink != null) { _sink = otherSink; _source = mySource; } base.ConnectSinkToSource(_sink, _source); outlet.ConnectPlug(this); connectedOutlet = outlet; pluggedIn?.Invoke(outlet.GetComponent <Rigidbody2D>()); }
/// <summary> /// Finds the nearest avialable thermalsource and update effective part mass /// </summary> public void FindAndAttachToPowerSource() { partDistance = 0; // disconnect if (attachedPowerSource != null) { if (chargedParticleMode) { attachedPowerSource.ConnectedChargedParticleElectricGenerator = null; } else { attachedPowerSource.ConnectedThermalElectricGenerator = null; } } // first look if part contains an thermal source attachedPowerSource = part.FindModulesImplementing <IPowerSource>().FirstOrDefault(); if (attachedPowerSource != null) { ConnectToPowerSource(); Debug.Log("[KSPI] - Found power source localy"); return; } if (!part.attachNodes.Any() || part.attachNodes.All(m => m.attachedPart == null)) { Debug.Log("[KSPI] - not connected to any parts yet"); UpdateTargetMass(); return; } Debug.Log("[KSPI] - generator is currently connected to " + part.attachNodes.Count + " parts"); // otherwise look for other non selfcontained thermal sources that is not already connected PowerSourceSearchResult searchResult = chargedParticleMode ? FindChargedParticleSource() : FindThermalPowerSource(); // quit if we failed to find anything if (searchResult == null) { Debug.LogWarning("[KSPI] - Failed to find power source"); return; } // verify cost is not higher than 1 partDistance = (int)Math.Max(Math.Ceiling(searchResult.Cost), 0); if (partDistance > 1) { Debug.LogWarning("[KSPI] - Found power source but at too high cost"); return; } // update attached thermalsource attachedPowerSource = searchResult.Source; Debug.Log("[KSPI] - succesfully connected to " + attachedPowerSource.Part.partInfo.title); ConnectToPowerSource(); }
public static uint Draw(uint amt, IPowerSource src, Action onNotEnoughEnergy = null) { try { src.ExpendEnergy(amt); } catch (NotEnoughEnergyException) { DoOrThrow(onNotEnoughEnergy, new NotEnoughEnergyException( )); } return(amt); }
public SuperSaiyanLamp(string name, IPowerSource powerSource) { this.Name = name; this.AmpsNeeded = 1500; this.MaximumVoltage = 120; this.Lumens = 9001; // It's over 9000! this.powerSource = powerSource; }
// "Don't look for things; ask for things" // Simply take our dependency (powerSource) as a constructor argument public FloorLamp(string name, IPowerSource powerSource) { this.Name = name; this.AmpsNeeded = 15; this.MaximumVoltage = 120; this.Lumens = 30; this.powerSource = powerSource; }
public bool PowerSourceFitsCase(IPowerSource source) { if (source.Width <= Case.Width && source.Length <= Case.Length && source.Height <= Case.Height) { return(true); } return(false); }
private void Awake() { IPowerSource source = powerSource as IPowerSource; IPowerSink sink = powerSink as IPowerSink; if (source != null && sink != null) { base.ConnectSinkToSource(sink, source); } else { Debug.LogWarning($"Could not connect {powerSource.name} as a source to {powerSink.name} as a sink!"); } }
//look through all of the array elements and add up private void DivideList(List <GameObject> mainList, List <IPowerSource> powerList, List <IPoweredDevice> deviceList) { foreach (var item in mainList) { IPowerSource p = item.GetComponent <IPowerSource>(); if (p != null) { powerList.Add(p); } IPoweredDevice s = item.GetComponent <IPoweredDevice>(); if (s != null) { deviceList.Add(s); } } }
private void button1_Click(object sender, EventArgs e) { richTextBox1.Clear(); IOutput output = new TextBoxOutput(this); var headsetType = (HeadsetsFactory.HeadsetType)listBox1.SelectedItem; var headsets = new HeadsetsFactory(); IPlayback playbackDevice = headsets.GetHeadset(headsetType, output); output.Write("Set playback to mobile..."); playbackDevice.Play(new Sound()); var chargerType = (ChargersFactory.ChargerType)listBox2.SelectedItem; var chargers = new ChargersFactory(); IPowerSource powerSource = chargers.GetPowerSource(chargerType, 2.4f, 5f); output.Write("Charger type:"); output.Write(powerSource.ToString()); }
public void OnDisconnect(IPowerSource source) { _source = null; }
public void OnConnect(IPowerSource source) { _source = source; }
public void Reset() { _currCharge = _startingCharge; _source = null; }
public PowerSourceSearchResult(IPowerSource source, float cost) { Cost = cost; Source = source; }
public virtual void ConnectSinkToSource(IPowerSink sink, IPowerSource source) { source.OnConnect(sink); sink.OnConnect(source); }
public CoffeeMaker(IPowerSource powerSource) { this.powerSource = powerSource; }
public void OnDisconnect(IPowerSource src) { source = null; isPowered = false; OnPowerLost?.Invoke(); }
public void OnConnect(IPowerSource src) { source = src; }
public uint DrawEnergy(uint amt, IPowerSource energySource, Action onNotEnoughEnergy = null) => throw new NotImplementedException( );
public virtual void DisconnectSinkFromSource(IPowerSink sink, IPowerSource source) { source.OnDisconnect(sink); sink.OnDisconnect(source); }