Пример #1
0
    void Interact()
    {
        if (canister)
        {
            return;
        }
        Pickupable held = PlayerController.instance.charController.heldObject;

        if (held)
        {
            held.Drop();
            canister = held.GetComponent <Canister>();
            canister.transform.SetParent(transform);
            canister.transform.rotation      = Quaternion.identity;
            canister.transform.localPosition = new Vector3(0, 0.25f, 0);
            canister.GetComponent <Rigidbody2D>().simulated = false;
            canister.GetComponent <Collider2D>().enabled    = true;
        }
    }
Пример #2
0
    /// <summary>
    /// switch the secondary valve between internals valve and external tank
    /// </summary>
    /// <param name="usingTank">Is the valve set to tank.</param>
    public void ServerToggleSecondary(bool usingTank)
    {
        tankValveOpen = usingTank;
        Canister     canister     = Provider.GetComponent <Canister>();
        GasContainer canisterTank = canister.GetComponent <GasContainer>();
        GasContainer externalTank = canister.InsertedContainer?.GetComponent <GasContainer>();

        if (usingTank && externalTank != null)
        {
            GasMix  canisterGas          = canisterTank.GasMix;
            GasMix  tankGas              = externalTank.GasMix;
            float[] updatedCanisterGases = { 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f };
            float[] updatedTankGases     = { 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f };
            float   updatedTankMoles     = 0f;

            GasMix  totalGas   = canisterGas + tankGas;
            float[] totalGases = totalGas.Gases;

            //while: canister has greater pressure than external tank AND tank isn't full
            while (canisterTank.ServerInternalPressure >= externalTank.ServerInternalPressure &&
                   updatedTankMoles <= externalTank.MaximumMoles)
            {
                //iterate through gases and distribute between the canister and external tank
                for (int i = 0; i < totalGases.Length; i++)
                {
                    if (totalGases[i] > 0f && updatedTankMoles <= externalTank.MaximumMoles)
                    {
                        totalGases[i]           -= 0.02f;
                        updatedCanisterGases[i] += 0.01f;
                        updatedTankGases[i]     += 0.01f;
                        updatedTankMoles        += 0.01f;
                    }
                }
            }
            //add remaining gases to the canister values
            for (int i = 0; i < totalGases.Length; i++)
            {
                if (totalGases[i] > 0f)
                {
                    updatedCanisterGases[i] += totalGases[i];
                    totalGases[i]            = 0f;
                    //compensate for valve blowoff
                    updatedCanisterGases[i] -= 0.02052f;
                }
            }

            //make sure we're not marginally increasing gas in the tank
            //due to float falloff
            bool accuracyCheck = true;
            for (int i = 0; i < canisterTank.Gases.Length; i++)
            {
                if (canisterTank.Gases[i] < updatedCanisterGases[i])
                {
                    accuracyCheck = false;
                }
            }
            if (accuracyCheck)
            {
                canisterTank.Gases = updatedCanisterGases;
                canisterTank.UpdateGasMix();
            }
            externalTank.Gases = updatedTankGases;
            externalTank.UpdateGasMix();
            ExternalPressureDial.ServerSpinTo(Mathf.RoundToInt(externalTank.ServerInternalPressure));
        }
        else if (usingTank && externalTank == null)
        {
            StartCoroutine(DisplayFlashingText("Insert a tank before opening the valve!", 1F));
        }
    }