コード例 #1
0
ファイル: Plug.cs プロジェクト: davidhenshaw/Extension_Game
    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>());
    }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
 public static uint Draw(uint amt, IPowerSource src, Action onNotEnoughEnergy = null)
 {
     try {
         src.ExpendEnergy(amt);
     } catch (NotEnoughEnergyException) {
         DoOrThrow(onNotEnoughEnergy, new NotEnoughEnergyException( ));
     }
     return(amt);
 }
コード例 #4
0
        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;
        }
コード例 #5
0
        // "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;
        }
コード例 #6
0
        public bool PowerSourceFitsCase(IPowerSource source)
        {
            if (source.Width <= Case.Width &&
                source.Length <= Case.Length &&
                source.Height <= Case.Height)
            {
                return(true);
            }

            return(false);
        }
コード例 #7
0
    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!");
        }
    }
コード例 #8
0
    //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);
            }
        }
    }
コード例 #9
0
        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());
        }
コード例 #10
0
 public void OnDisconnect(IPowerSource source)
 {
     _source = null;
 }
コード例 #11
0
 public void OnConnect(IPowerSource source)
 {
     _source = source;
 }
コード例 #12
0
 public void Reset()
 {
     _currCharge = _startingCharge;
     _source     = null;
 }
コード例 #13
0
 public PowerSourceSearchResult(IPowerSource source, float cost)
 {
     Cost   = cost;
     Source = source;
 }
コード例 #14
0
 public virtual void ConnectSinkToSource(IPowerSink sink, IPowerSource source)
 {
     source.OnConnect(sink);
     sink.OnConnect(source);
 }
コード例 #15
0
 public CoffeeMaker(IPowerSource powerSource)
 {
     this.powerSource = powerSource;
 }
コード例 #16
0
 public void OnDisconnect(IPowerSource src)
 {
     source    = null;
     isPowered = false;
     OnPowerLost?.Invoke();
 }
コード例 #17
0
 public void OnConnect(IPowerSource src)
 {
     source = src;
 }
コード例 #18
0
 public uint DrawEnergy(uint amt, IPowerSource energySource, Action onNotEnoughEnergy = null) => throw new NotImplementedException( );
コード例 #19
0
 public virtual void DisconnectSinkFromSource(IPowerSink sink, IPowerSource source)
 {
     source.OnDisconnect(sink);
     sink.OnDisconnect(source);
 }