コード例 #1
0
 private void OnMagazineSlotChange(EntityUid uid, MagazineAmmoProviderComponent component, ref ItemSlotChangedEvent args)
 {
     UpdateAmmoCount(uid);
     if (!TryComp <AppearanceComponent>(uid, out var appearance))
     {
         return;
     }
     appearance.SetData(AmmoVisuals.MagLoaded, GetMagazineEntity(uid) != null);
 }
コード例 #2
0
    private void EjectMagazine(MagazineAmmoProviderComponent component)
    {
        var ent = GetMagazineEntity(component.Owner);

        if (ent == null)
        {
            return;
        }

        _slots.TryEject(component.Owner, MagazineSlot, null, out var a, excludeUserAudio: true);
    }
コード例 #3
0
    private void FinaliseMagazineTakeAmmo(EntityUid uid, MagazineAmmoProviderComponent component, TakeAmmoEvent args, int count, int capacity, AppearanceComponent?appearance)
    {
        // If no ammo then check for autoeject
        if (component.AutoEject && args.Ammo.Count == 0)
        {
            EjectMagazine(component);
            PlaySound(uid, component.SoundAutoEject?.GetSound(Random, ProtoManager), args.User);
        }

        UpdateMagazineAppearance(appearance, true, count, capacity);
    }
コード例 #4
0
    private void OnMagazineActivate(EntityUid uid, MagazineAmmoProviderComponent component, ActivateInWorldEvent args)
    {
        var magEnt = GetMagazineEntity(uid);

        if (magEnt == null)
        {
            return;
        }

        RaiseLocalEvent(magEnt.Value, args, false);
        UpdateAmmoCount(uid);
        UpdateMagazineAppearance(component, magEnt.Value);
    }
コード例 #5
0
    private void OnMagazineVerb(EntityUid uid, MagazineAmmoProviderComponent component, GetVerbsEvent <Verb> args)
    {
        if (!args.CanInteract || !args.CanAccess)
        {
            return;
        }

        var magEnt = GetMagazineEntity(uid);

        if (magEnt != null)
        {
            RaiseLocalEvent(magEnt.Value, args, false);
            UpdateMagazineAppearance(component, magEnt.Value);
        }
    }
コード例 #6
0
    private void OnMagazineAmmoUpdate(EntityUid uid, MagazineAmmoProviderComponent component, UpdateAmmoCounterEvent args)
    {
        var ent = GetMagazineEntity(uid);

        if (ent == null)
        {
            if (args.Control is DefaultStatusControl control)
            {
                control.Update(0, 0);
            }

            return;
        }

        RaiseLocalEvent(ent.Value, args, false);
    }
コード例 #7
0
    protected (int, int) GetMagazineCountCapacity(MagazineAmmoProviderComponent component)
    {
        var count    = 0;
        var capacity = 1;
        var magEnt   = GetMagazineEntity(component.Owner);

        if (magEnt != null)
        {
            var ev = new GetAmmoCountEvent();
            RaiseLocalEvent(magEnt.Value, ref ev, false);
            count    += ev.Count;
            capacity += ev.Capacity;
        }

        return(count, capacity);
    }
コード例 #8
0
    private void OnMagazineTakeAmmo(EntityUid uid, MagazineAmmoProviderComponent component, TakeAmmoEvent args)
    {
        var magEntity = GetMagazineEntity(uid);

        TryComp <AppearanceComponent>(uid, out var appearance);

        if (magEntity == null)
        {
            appearance?.SetData(AmmoVisuals.MagLoaded, false);
            return;
        }

        // Pass the event onwards.
        RaiseLocalEvent(magEntity.Value, args, false);
        // Should be Dirtied by what other ammoprovider is handling it.

        var ammoEv = new GetAmmoCountEvent();

        RaiseLocalEvent(magEntity.Value, ref ammoEv, false);
        FinaliseMagazineTakeAmmo(uid, component, args, ammoEv.Count, ammoEv.Capacity, appearance);
    }
コード例 #9
0
    private void UpdateMagazineAppearance(MagazineAmmoProviderComponent component, EntityUid magEnt)
    {
        TryComp <AppearanceComponent>(component.Owner, out var appearance);

        var count    = 0;
        var capacity = 0;

        if (component is ChamberMagazineAmmoProviderComponent chamber)
        {
            count    = GetChamberEntity(chamber.Owner) != null ? 1 : 0;
            capacity = 1;
        }

        if (TryComp <AppearanceComponent>(magEnt, out var magAppearance))
        {
            magAppearance.TryGetData <int>(AmmoVisuals.AmmoCount, out var addCount);
            magAppearance.TryGetData <int>(AmmoVisuals.AmmoMax, out var addCapacity);
            count    += addCount;
            capacity += addCapacity;
        }

        UpdateMagazineAppearance(appearance, true, count, capacity);
    }
コード例 #10
0
 private void OnMagazineExamine(EntityUid uid, MagazineAmmoProviderComponent component, ExaminedEvent args)
 {
     var(count, _) = GetMagazineCountCapacity(component);
     args.PushMarkup(Loc.GetString("gun-magazine-examine", ("color", AmmoExamineColor), ("count", count)));
 }