protected virtual void OnTriggerEnter2D(Collider2D other)
    {
        PlayerGridObject player = other.GetComponent <PlayerGridObject>();

        if (player)
        {
            OxygenLevel oxygen = other.GetComponent <OxygenLevel>();
            if (oxygen)
            {
                oxygen.RefillOxygen();
            }
            Destroy(gameObject);
        }
    }
Beispiel #2
0
    public void Run(ZACommons commons, EventDriver eventDriver)
    {
        var tanks = ZACommons.GetBlocksOfType <IMyGasTank>(commons.AllBlocks,
                                                           tank => tank.IsFunctional &&
                                                           tank.IsWorking &&
                                                           tank.CustomName.IndexOf("[Excluded]", ZACommons.IGNORE_CASE) < 0);

        var currentState = GetOxygenState(tanks);

        // Only act on level transitions
        if (PreviousState != currentState)
        {
            PreviousState = currentState;

            // We need a tri-state variable, so... nullable
            bool?generateOxygen = null;
            bool?farmOxygen     = null;

            switch (currentState)
            {
            case OxygenLevel.High:
                // Turn off all oxygen production
                generateOxygen = false;
                farmOxygen     = false;
                break;

            case OxygenLevel.Normal:
                // Do nothing (but keep farms up)
                farmOxygen = true;
                break;

            case OxygenLevel.Buffer:
                // Start producing oxygen
                generateOxygen = true;
                farmOxygen     = true;
                break;

            case OxygenLevel.Low:
                // Definitely start producing oxygen
                generateOxygen = true;
                farmOxygen     = true;
                // For now, it's intentional that we start timer blocks
                // on all grids... we'll see how it goes
                TimerBlockUtils.StartTimerBlockWithName(commons.AllBlocks, LOW_OXYGEN_NAME);
                break;
            }

            if (generateOxygen != null)
            {
                // Limit to this grid -- don't mess with any other ship's systems
                var generators =
                    ZACommons.GetBlocksOfType <IMyGasGenerator>(commons.Blocks,
                                                                block => block.IsFunctional);
                ZACommons.EnableBlocks(generators, (bool)generateOxygen);
            }
            if (farmOxygen != null)
            {
                var farms =
                    ZACommons.GetBlocksOfType <IMyOxygenFarm>(commons.Blocks,
                                                              block => block.IsFunctional);

                // Farms don't implement IMyFunctionalBlock??
                ZACommons.EnableBlocks(farms, (bool)farmOxygen);

                // We'll count atmosphere intake vents too, since they're "free"
                var vents =
                    ZACommons.GetBlocksOfType <IMyAirVent>(commons.Blocks,
                                                           vent => vent.IsFunctional &&
                                                           vent.Depressurize &&
                                                           vent.CustomName.IndexOf("[Intake]", ZACommons.IGNORE_CASE) >= 0);

                ZACommons.EnableBlocks(vents, (bool)farmOxygen);
            }
        }

        eventDriver.Schedule(RunDelay, Run);
    }