コード例 #1
0
    private void OnChargeChanged(EntityUid uid, PowerCellComponent component, ChargeChangedEvent args)
    {
        if (component.IsRigged)
        {
            Explode(uid);
            return;
        }

        if (!TryComp(uid, out BatteryComponent? battery))
        {
            return;
        }

        if (!TryComp(uid, out AppearanceComponent? appearance))
        {
            return;
        }

        var frac  = battery.CurrentCharge / battery.MaxCharge;
        var level = (byte)ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);

        appearance.SetData(PowerCellVisuals.ChargeLevel, level);

        // If this power cell is inside a cell-slot, inform that entity that the power has changed (for updating visuals n such).
        if (_containerSystem.TryGetContainingContainer(uid, out var container) &&
            TryComp(container.Owner, out PowerCellSlotComponent? slot) &&
            slot.CellSlot.Item == uid)
        {
            RaiseLocalEvent(container.Owner, new PowerCellChangedEvent(false), false);
        }
    }
コード例 #2
0
 // Change the APC's state only when the battery state changes, or when it's first created.
 private void OnBatteryChargeChanged(EntityUid uid, ApcComponent component, ChargeChangedEvent args)
 {
     UpdateApcState(uid, component);
 }
コード例 #3
0
 private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ChargeChangedEvent args)
 {
     UpdateShots(uid, component);
 }