コード例 #1
0
        /// <summary>
        /// <para>Replaces, builds a new electrical connection, and consumes
        /// cables from the hand.</para>
        /// <para>Destroys the electrical connection (if we're given one) and
        /// then adds a new electrical connection by adding an electrical
        /// node. We then calculate and consume a number of cables from the
        /// hand.</para>
        /// </summary>
        /// <param name="position">Position of the electrical connection.</param>
        /// <param name="eConn">Electrical connection we're replacing.</param>
        /// <param name="wireEndA">Connection direction of one end.</param>
        /// <param name="wireEndB">Connection direction of the other end.</param>
        private void ReplaceEConn(Vector3 position, IntrinsicElectronicData eConn, Connection wireEndA,
                                  Connection wireEndB, ConnectionApply interaction)
        {
            // Cost of cable coils to construct the original cable tile. Assume
            // 0 until we verify whether or not we are given an electrical
            // connection.
            int oldTileCost = 0;

            // Get the cost of the old tile. Then destroy the current
            // electrical connection only if we were given a connection.
            if (eConn != null)
            {
                oldTileCost = eConn.MetaDataPresent.RelatedTile.SpawnAmountOnDeconstruct;
                eConn.DestroyThisPlease();
            }

            // Get the electrical cable tile with the wire connection direction.
            ElectricalCableTile tile =
                ElectricityFunctions.RetrieveElectricalTile(wireEndA, wireEndB, powerTypeCategory);

            // Then, add an electrical node at the tile.
            interaction.Performer.GetComponentInParent <Matrix>().AddElectricalNode(position.RoundToInt(), tile, true);

            // We only want to consume the difference needed to build the new
            // cable.
            int newTileCost = tile.SpawnAmountOnDeconstruct;
            int finalCost   = newTileCost - oldTileCost;

            // Finally, consume the cables in the hands using the final cost
            // we found.
            Inventory.ServerConsume(interaction.HandSlot, finalCost);
        }
コード例 #2
0
ファイル: MouseAI.cs プロジェクト: unitystation/unitystation
        private void WireChew(IntrinsicElectronicData cable)
        {
            ElectricityFunctions.WorkOutActualNumbers(cable);
            float voltage = cable.Data.ActualVoltage;

            // Remove the cable and spawn the item.
            cable.DestroyThisPlease();
            var electricalTile = registerObject.TileChangeManager.MetaTileMap.GetTile(registerObject.WorldPosition, LayerType.Underfloor) as ElectricalCableTile;

            // Electrical tile is not null iff this is the first mousechew. Why?
            if (electricalTile != null)
            {
                Spawn.ServerPrefab(electricalTile.SpawnOnDeconstruct, registerObject.WorldPosition,
                                   count: electricalTile.SpawnAmountOnDeconstruct);
            }

            Electrocute(voltage);
        }