Exemple #1
0
 public void CycleRevolver(RevolverBarrelComponent component)
 {
     // Move up a slot
     component.CurrentSlot = (component.CurrentSlot + 1) % component.AmmoSlots.Length;
     component.Dirty(EntityManager);
     UpdateRevolverAppearance(component);
 }
Exemple #2
0
    public bool TryInsertBullet(EntityUid user, EntityUid entity, RevolverBarrelComponent component)
    {
        if (!TryComp(entity, out AmmoComponent? ammoComponent))
        {
            return(false);
        }

        if (ammoComponent.Caliber != component.Caliber)
        {
            _popup.PopupEntity(Loc.GetString("revolver-barrel-component-try-insert-bullet-wrong-caliber"), component.Owner, Filter.Entities(user));
            return(false);
        }

        // Functions like a stack
        // These are inserted in reverse order but then when fired Cycle will go through in order
        // The reason we don't just use an actual stack is because spin can select a random slot to point at
        for (var i = component.AmmoSlots.Length - 1; i >= 0; i--)
        {
            var slot = component.AmmoSlots[i];
            if (slot == default)
            {
                component.CurrentSlot  = i;
                component.AmmoSlots[i] = entity;
                component.AmmoContainer.Insert(entity);
                SoundSystem.Play(Filter.Pvs(component.Owner), component.SoundInsert.GetSound(), component.Owner, AudioParams.Default.WithVolume(-2));

                component.Dirty(EntityManager);
                UpdateRevolverAppearance(component);
                return(true);
            }
        }

        _popup.PopupEntity(Loc.GetString("revolver-barrel-component-try-insert-bullet-ammo-full"), ammoComponent.Owner, Filter.Entities(user));
        return(false);
    }
Exemple #3
0
    private void OnRevolverMapInit(EntityUid uid, RevolverBarrelComponent component, MapInitEvent args)
    {
        component.UnspawnedCount = component.Capacity;
        var idx = 0;

        component.AmmoContainer = component.Owner.EnsureContainer <Container>($"{component.GetType()}-ammoContainer", out var existing);
        if (existing)
        {
            foreach (var entity in component.AmmoContainer.ContainedEntities)
            {
                component.UnspawnedCount--;
                component.AmmoSlots[idx] = entity;
                idx++;
            }
        }

        // TODO: Revolvers should also defer spawning T B H
        var xform = EntityManager.GetComponent <TransformComponent>(uid);

        for (var i = 0; i < component.UnspawnedCount; i++)
        {
            var entity = EntityManager.SpawnEntity(component.FillPrototype, xform.Coordinates);
            component.AmmoSlots[idx] = entity;
            component.AmmoContainer.Insert(entity);
            idx++;
        }

        UpdateRevolverAppearance(component);
        component.Dirty(EntityManager);
    }
Exemple #4
0
    /// <summary>
    /// Russian Roulette
    /// </summary>
    public void SpinRevolver(RevolverBarrelComponent component)
    {
        var random = _random.Next(component.AmmoSlots.Length - 1);

        component.CurrentSlot = random;
        SoundSystem.Play(Filter.Pvs(component.Owner), component.SoundSpin.GetSound(), component.Owner, AudioParams.Default.WithVolume(-2));
        component.Dirty(EntityManager);
    }
Exemple #5
0
    private void OnRevolverUse(EntityUid uid, RevolverBarrelComponent component, UseInHandEvent args)
    {
        if (args.Handled)
        {
            return;
        }

        EjectAllSlots(component);
        component.Dirty(EntityManager);
        UpdateRevolverAppearance(component);
        args.Handled = true;
    }