Ejemplo n.º 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);
        }
    }
Ejemplo n.º 2
0
    private void OnCellExamined(EntityUid uid, PowerCellComponent component, ExaminedEvent args)
    {
        if (!TryComp(uid, out BatteryComponent? battery))
        {
            return;
        }

        var charge = battery.CurrentCharge / battery.MaxCharge * 100;

        args.PushMarkup(Loc.GetString("power-cell-component-examine-details", ("currentCharge", $"{charge:F0}")));
    }
Ejemplo n.º 3
0
    private void OnSolutionChange(EntityUid uid, PowerCellComponent component, SolutionChangedEvent args)
    {
        component.IsRigged = _solutionsSystem.TryGetSolution(uid, PowerCellComponent.SolutionName, out var solution) &&
                             solution.ContainsReagent("Plasma", out var plasma) &&
                             plasma >= 5;

        if (component.IsRigged)
        {
            _logSystem.Add(LogType.Explosion, LogImpact.Medium, $"Power cell {ToPrettyString(uid)} has been rigged up to explode when used.");
        }
    }
Ejemplo n.º 4
0
 private void OnSolutionChange(EntityUid uid, PowerCellComponent component, SolutionChangedEvent args)
 {
     component.IsRigged = _solutionsSystem.TryGetSolution(uid, PowerCellComponent.SolutionName, out var solution) &&
                          solution.ContainsReagent("Plasma", out var plasma) &&
                          plasma >= 5;
 }