Add IItemStatus to some weapon types (#1879)
* Bolt Action * Shotguns * Revolver + Outline * In Magazines: show bullets as numbers plus the usual bullet stuff * Empty bullets have another texture
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
@@ -32,6 +33,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
// but it felt a lot messier to play around with, especially when adding verbs
|
||||
|
||||
public override string Name => "BoltActionBarrel";
|
||||
public override uint? NetID => ContentNetIDs.BOLTACTION_BARREL;
|
||||
|
||||
public override int ShotsLeft
|
||||
{
|
||||
@@ -123,6 +125,24 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
(int, int)? count = (ShotsLeft, Capacity);
|
||||
var chamberedExists = _chamberContainer.ContainedEntity != null;
|
||||
// (Is one chambered?, is the bullet spend)
|
||||
var chamber = (chamberedExists, false);
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
{
|
||||
chamber.Item2 = ammo.Spent;
|
||||
}
|
||||
|
||||
return new BoltActionBarrelComponentState(
|
||||
chamber,
|
||||
FireRateSelector,
|
||||
count,
|
||||
SoundGunshot);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
// TODO: Add existing ammo support on revolvers
|
||||
@@ -170,6 +190,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
Cycle();
|
||||
}
|
||||
else
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAtGrid, spawnAtMap);
|
||||
}
|
||||
|
||||
@@ -256,7 +281,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
@@ -269,7 +294,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
@@ -27,6 +28,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit, IExamine
|
||||
{
|
||||
public override string Name => "PumpBarrel";
|
||||
public override uint? NetID => ContentNetIDs.PUMP_BARREL;
|
||||
|
||||
public override int ShotsLeft
|
||||
{
|
||||
@@ -81,6 +83,23 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
(int, int)? count = (ShotsLeft, Capacity);
|
||||
var chamberedExists = _chamberContainer.ContainedEntity != null;
|
||||
// (Is one chambered?, is the bullet spend)
|
||||
var chamber = (chamberedExists, false);
|
||||
if (chamberedExists && _chamberContainer.ContainedEntity.TryGetComponent<AmmoComponent>(out var ammo))
|
||||
{
|
||||
chamber.Item2 = ammo.Spent;
|
||||
}
|
||||
return new PumpBarrelComponentState(
|
||||
chamber,
|
||||
FireRateSelector,
|
||||
count,
|
||||
SoundGunshot);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -110,6 +129,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
@@ -131,6 +151,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
Cycle();
|
||||
}
|
||||
else
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
|
||||
return chamberEntity?.GetComponent<AmmoComponent>().TakeBullet(spawnAtGrid, spawnAtMap);
|
||||
}
|
||||
|
||||
@@ -168,7 +193,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
}
|
||||
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
@@ -189,7 +214,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
_ammoContainer.Insert(eventArgs.Using);
|
||||
_spawnedAmmo.Push(eventArgs.Using);
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
if (_soundInsert != null)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
@@ -25,6 +26,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public sealed class RevolverBarrelComponent : ServerRangedBarrelComponent
|
||||
{
|
||||
public override string Name => "RevolverBarrel";
|
||||
public override uint? NetID => ContentNetIDs.REVOLVER_BARREL;
|
||||
|
||||
private BallisticCaliber _caliber;
|
||||
private Container _ammoContainer;
|
||||
private int _currentSlot = 0;
|
||||
@@ -60,6 +63,26 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
serializer.DataField(ref _soundSpin, "soundSpin", "/Audio/Weapons/Guns/Misc/revolver_spin.ogg");
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
var slotsSpent = new bool?[Capacity];
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
slotsSpent[i] = null;
|
||||
if (_ammoSlots[i] != null && _ammoSlots[i].TryGetComponent(out AmmoComponent ammo))
|
||||
{
|
||||
slotsSpent[i] = ammo.Spent;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: make yaml var to not sent currentSlot/UI? (for russian roulette)
|
||||
return new RevolverBarrelComponentState(
|
||||
_currentSlot,
|
||||
FireRateSelector,
|
||||
slotsSpent,
|
||||
SoundGunshot);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -90,6 +113,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
@@ -129,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundInsert, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
@@ -143,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
// Move up a slot
|
||||
_currentSlot = (_currentSlot + 1) % _ammoSlots.Length;
|
||||
// Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
@@ -158,6 +182,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundSpin, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override IEntity PeekAmmo()
|
||||
@@ -227,7 +252,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
EjectAllSlots();
|
||||
//Dirty();
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user