Speedloader fix (#12417)
* Speedloader fix * Unshitted and commented my code, rain would probably be proud.
This commit is contained in:
@@ -6,6 +6,8 @@ using Robust.Shared.Containers;
|
|||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Content.Shared.Weapons.Ranged.Systems;
|
namespace Content.Shared.Weapons.Ranged.Systems;
|
||||||
|
|
||||||
@@ -73,8 +75,69 @@ public partial class SharedGunSystem
|
|||||||
|
|
||||||
public bool TryRevolverInsert(RevolverAmmoProviderComponent component, EntityUid uid, EntityUid? user)
|
public bool TryRevolverInsert(RevolverAmmoProviderComponent component, EntityUid uid, EntityUid? user)
|
||||||
{
|
{
|
||||||
if (component.Whitelist?.IsValid(uid, EntityManager) == false) return false;
|
if (component.Whitelist?.IsValid(uid, EntityManager) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (EntityManager.HasComponent<BallisticAmmoProviderComponent>(uid)) // Checks if the thing that's being used to reload the revolver is a quickloader
|
||||||
|
{
|
||||||
|
var ammoComp = EntityManager.GetComponent<BallisticAmmoProviderComponent>(uid);
|
||||||
|
|
||||||
|
if (ammoComp.UnspawnedCount + ammoComp.Entities.Count == 0) // Checks if there's no ammo left in the speedloader
|
||||||
|
{
|
||||||
|
Popup(Loc.GetString("gun-speedloader-empty"), component.Owner, user); // Tell the user that the speedloader is empty
|
||||||
|
return false; // Don't try to insert anything into the revolver.
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadedBullet = false; // Used later
|
||||||
|
|
||||||
|
for (var i = 0; i < component.Capacity; i++)
|
||||||
|
{
|
||||||
|
if (ammoComp.UnspawnedCount + ammoComp.Entities.Count == 0) // Checks if there's any ammo left in the speedloader in the loop
|
||||||
|
continue; // The loop doesn't continue, this is a fucking lie! I HATE C#!!!
|
||||||
|
|
||||||
|
var index = (component.CurrentIndex + i) % component.Capacity;
|
||||||
|
|
||||||
|
if (component.AmmoSlots[index] != null ||
|
||||||
|
component.Chambers[index] != null) continue;
|
||||||
|
|
||||||
|
loadedBullet = true; // Used later
|
||||||
|
|
||||||
|
var xform = EntityManager.GetComponent<TransformComponent>(uid);
|
||||||
|
EntityUid bullet; // empty var that is guarenteed to be filled
|
||||||
|
|
||||||
|
if (ammoComp.Container.ContainedEntities.Count == 0) // If the entity doesn't have any spawned bullets
|
||||||
|
{
|
||||||
|
ammoComp.UnspawnedCount -= 1;
|
||||||
|
bullet = Spawn(ammoComp.FillProto, xform.MapPosition); // Spawn it in
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bullet = ammoComp.Container.ContainedEntities.FirstOrNull()!.Value;
|
||||||
|
ammoComp.Entities.Remove(bullet); // Remove the bullet from the container, ensures no bugs happen with the quickloader.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loads the bullet into the chamber of the revolver
|
||||||
|
component.AmmoSlots[index] = bullet;
|
||||||
|
component.AmmoContainer.Insert(bullet);
|
||||||
|
UpdateBallisticAppearance(ammoComp);
|
||||||
|
UpdateRevolverAppearance(component);
|
||||||
|
UpdateAmmoCount(bullet);
|
||||||
|
Dirty(component);
|
||||||
|
}
|
||||||
|
if (!loadedBullet) // Used now, if true, do funny sound + do popup, otherwise do popup to say that the revolver is full
|
||||||
|
{
|
||||||
|
Popup(Loc.GetString("gun-revolver-full"), component.Owner, user);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Audio.PlayPredicted(component.SoundInsert, component.Owner, user);
|
||||||
|
Popup(Loc.GetString("gun-revolver-insert"), component.Owner, user);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (var i = 0; i < component.Capacity; i++)
|
for (var i = 0; i < component.Capacity; i++)
|
||||||
{
|
{
|
||||||
var index = (component.CurrentIndex + i) % component.Capacity;
|
var index = (component.CurrentIndex + i) % component.Capacity;
|
||||||
@@ -91,10 +154,10 @@ public partial class SharedGunSystem
|
|||||||
Dirty(component);
|
Dirty(component);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Popup(Loc.GetString("gun-revolver-full"), component.Owner, user);
|
Popup(Loc.GetString("gun-revolver-full"), component.Owner, user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnRevolverVerbs(EntityUid uid, RevolverAmmoProviderComponent component, GetVerbsEvent<Verb> args)
|
private void OnRevolverVerbs(EntityUid uid, RevolverAmmoProviderComponent component, GetVerbsEvent<Verb> args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,3 +32,4 @@ gun-revolver-full = Revolver full
|
|||||||
gun-revolver-insert = Inserted
|
gun-revolver-insert = Inserted
|
||||||
gun-revolver-spin = Spin revolver
|
gun-revolver-spin = Spin revolver
|
||||||
gun-revolver-spun = Spun
|
gun-revolver-spun = Spun
|
||||||
|
gun-speedloader-empty = Speedloader empty
|
||||||
@@ -566,6 +566,7 @@
|
|||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeCap
|
- CartridgeCap
|
||||||
|
- SpeedLoaderCap
|
||||||
proto: CartridgeCap
|
proto: CartridgeCap
|
||||||
capacity: 6
|
capacity: 6
|
||||||
chambers: [ True, True, True, True, True, True ]
|
chambers: [ True, True, True, True, True, True ]
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- SpeedLoaderMagnum
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- SpeedLoaderPistol
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
name: "speed loader (.30 rifle)"
|
name: "speed loader (.30 rifle)"
|
||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
components:
|
components:
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- SpeedLoaderRifle
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
abstract: true
|
abstract: true
|
||||||
components:
|
components:
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- SpeedLoaderCap
|
||||||
- type: BallisticAmmoProvider
|
- type: BallisticAmmoProvider
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- CartridgeMagnum
|
- CartridgeMagnum
|
||||||
|
- SpeedLoaderMagnum
|
||||||
proto: CartridgeMagnum
|
proto: CartridgeMagnum
|
||||||
capacity: 7
|
capacity: 7
|
||||||
chambers: [ True, True, True, True, True, True, True ]
|
chambers: [ True, True, True, True, True, True, True ]
|
||||||
|
|||||||
@@ -377,6 +377,9 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: NoSpinOnThrow
|
id: NoSpinOnThrow
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: NoBlockAnchoring
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: NukeOpsUplink
|
id: NukeOpsUplink
|
||||||
|
|
||||||
@@ -492,6 +495,18 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: Spear
|
id: Spear
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: SpeedLoaderCap
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: SpeedLoaderMagnum
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: SpeedLoaderPistol
|
||||||
|
|
||||||
|
- type: Tag
|
||||||
|
id: SpeedLoaderRifle
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: StringInstrument
|
id: StringInstrument
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user