Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedloaders for Internal Magazine Weapons #29807

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,48 @@ private void OnBallisticInteractUsing(EntityUid uid, BallisticAmmoProviderCompon
return;

if (GetBallisticShots(component) >= component.Capacity)
{
Popup(Loc.GetString("gun-ballistic-transfer-target-full", ("entity", args.Target)), uid, args.User);
return;
}

if (EntityManager.HasComponent<SpeedLoaderComponent>(args.Used))
{
Comment on lines +56 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this doubling the existing speedloaders? It's not even using a whitelist or anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by this? Doubling the existing speedloaders? It is also using a whitelist for anything inserted.
image

var emptySlots = component.Capacity - component.UnspawnedCount - component.Entities.Count; // Number of empty slots in the shotgun

var ammo = new List<(EntityUid? Entity, IShootable Shootable)>();
var ev = new TakeAmmoEvent(emptySlots, ammo, Transform(uid).Coordinates, args.User);
RaiseLocalEvent(args.Used, ev);

// empty speedloader
if (ev.Ammo.Count == 0)
{
Popup(Loc.GetString("gun-speedloader-empty"), uid, args.User);
return;
}

foreach (var (ent, _) in ammo)
{
if (ent == null)
continue;

component.Entities.Add(ent.Value);
Containers.Insert(ent.Value, component.Container);

if (IsClientSide(ent.Value))
Del(ent.Value);

Comment on lines +76 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this inserting then deleting it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what happens without the delete. OnBallisticAmmoFillDoAfter does the same thing

2024-08-08.21-51-03.mp4

if (ev.Ammo.Count == 0)
break;
Comment on lines +83 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event one is just a ref to the local variable, is this even possible here? It's being iterated in the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work, is there another way to do this that's preferred or is that fine?

2024-08-08.22-00-55.mp4

}
}
// if not a speedloader just insert
else
{
component.Entities.Add(args.Used);
Containers.Insert(args.Used, component.Container);
}

component.Entities.Add(args.Used);
Containers.Insert(args.Used, component.Container);
// Not predicted so
Audio.PlayPredicted(component.SoundInsert, uid, args.User);
args.Handled = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
- type: entity
id: SpeedLoaderLightRifle
id: BaseSpeedLoaderLightRifle
name: "speed loader (.30 rifle)"
parent: BaseItem
abstract: true
components:
- type: Tag
tags:
- SpeedLoaderRifle
- SpeedLoaderRifle
- type: SpeedLoader
- type: BallisticAmmoProvider
mayTransfer: true
whitelist:
tags:
- CartridgeLightRifle
capacity: 5
proto: CartridgeLightRifle
- CartridgeLightRifle
capacity: 6
- type: Sprite
sprite: Objects/Weapons/Guns/Ammunition/SpeedLoaders/LightRifle/light_rifle_speed_loader.rsi
- type: ContainerContainer
containers:
ballistic-ammo: !type:Container
ents: []

- type: entity
id: SpeedLoaderLightRifle
name: "speed loader (.30 rifle)"
parent: BaseSpeedLoaderLightRifle
components:
- type: BallisticAmmoProvider
proto: CartridgeLightRifle
- type: Sprite
layers:
- state: base
map: ["enum.GunVisualLayers.Base"]
Expand All @@ -26,7 +38,3 @@
steps: 6
zeroVisible: false
- type: Appearance
- type: ContainerContainer
containers:
ballistic-ammo: !type:Container
ents: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- type: entity
id: BaseSpeedLoaderShotgun
name: "speed loader (shotgun)"
parent: BaseItem
abstract: true
components:
- type: Tag
tags:
- SpeedLoaderShotgun
- type: SpeedLoader
- type: BallisticAmmoProvider
whitelist:
tags:
- ShellShotgun
capacity: 4
- type: Sprite
sprite: Objects/Weapons/Guns/Ammunition/SpeedLoaders/Shotgun/shotgun_speed_loader.rsi
- type: ContainerContainer
containers:
ballistic-ammo: !type:Container
ents: []

- type: entity
id: SpeedLoaderShotgun
name: "speed loader (shotgun)"
parent: BaseSpeedLoaderShotgun
components:
- type: BallisticAmmoProvider
proto: ShellShotgun
- type: Sprite
layers:
- state: base
map: ["enum.GunVisualLayers.Base"]
- state: base-4
map: ["enum.GunVisualLayers.Mag"]
- type: MagazineVisuals
magState: base
steps: 5
zeroVisible: false
- type: Appearance
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
- type: StaticPrice
price: 500

- type: entity
name: BaseWeaponShotgunSpeedLoadable
parent: BaseWeaponShotgun
id: BaseWeaponShotgunSpeedLoadable
abstract: true
components:
- type: BallisticAmmoProvider
whitelist:
tags:
- ShellShotgun
- SpeedLoaderShotgun

- type: entity
name: Bulldog
# Don't parent to BaseWeaponShotgun because it differs significantly
Expand Down Expand Up @@ -135,7 +147,7 @@

- type: entity
name: Enforcer
parent: [BaseWeaponShotgun, BaseGunWieldable]
parent: [BaseWeaponShotgunSpeedLoadable, BaseGunWieldable]
id: WeaponShotgunEnforcer
description: A premium combat shotgun based on the Kammerer design, featuring an upgraded clip capacity. .50 shotgun shells.
components:
Expand All @@ -158,7 +170,7 @@

- type: entity
name: Kammerer
parent: [BaseWeaponShotgun, BaseGunWieldable]
parent: [BaseWeaponShotgunSpeedLoadable, BaseGunWieldable]
id: WeaponShotgunKammerer
description: When an old Remington design meets modern materials, this is the result. A favourite weapon of militia forces throughout many worlds. Uses .50 shotgun shells.
components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
whitelist:
tags:
- CartridgeLightRifle
- SpeedLoaderRifle
- type: ContainerContainer
containers:
ballistic-ammo: !type:Container
Expand Down
5 changes: 4 additions & 1 deletion Resources/Prototypes/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@
- type: Tag
id: DrinkSpaceGlue

- type: Tag
- type: Tag
id: Dropper

- type: Tag
Expand Down Expand Up @@ -1176,6 +1176,9 @@
- type: Tag
id: SpeedLoaderRifle

- type: Tag
id: SpeedLoaderShotgun

- type: Tag
id: SpiderCraft

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 1,
"size": {
"x": 32,
"y": 32
},
"license": "CC0-1.0",
"copyright": "Created by @BluHNT from Nuclear-14 fork",
"states": [
{
"name": "base"
},
{
"name": "base-1"
},
{
"name": "base-2"
},
{
"name": "base-3"
},
{
"name": "base-4"
}
]
}
Loading