Storage system refactor & map init.
* Demonstrated map init working with guns, toolboxes, tool lockers. * Refactored EntityStorage and ServerStorage to have a common interface. * EntityStorage no longer uses ServerStorage PURELY for visuals. Use an appearance visualizer instead.
This commit is contained in:
@@ -3,31 +3,41 @@ using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
public class BallisticMagazineComponent : Component
|
||||
public class BallisticMagazineComponent : Component, IMapInit
|
||||
{
|
||||
public override string Name => "BallisticMagazine";
|
||||
|
||||
// Stack of loaded bullets.
|
||||
[ViewVariables]
|
||||
private readonly Stack<IEntity> _loadedBullets = new Stack<IEntity>();
|
||||
[ViewVariables]
|
||||
private string _fillType;
|
||||
|
||||
[ViewVariables]
|
||||
private Container _bulletContainer;
|
||||
[ViewVariables]
|
||||
private AppearanceComponent _appearance;
|
||||
|
||||
private BallisticMagazineType _magazineType;
|
||||
private BallisticCaliber _caliber;
|
||||
private int _capacity;
|
||||
|
||||
[ViewVariables]
|
||||
public BallisticMagazineType MagazineType => _magazineType;
|
||||
[ViewVariables]
|
||||
public BallisticCaliber Caliber => _caliber;
|
||||
[ViewVariables]
|
||||
public int Capacity => _capacity;
|
||||
|
||||
[ViewVariables]
|
||||
public int CountLoaded => _loadedBullets.Count;
|
||||
|
||||
public event Action OnAmmoCountChanged;
|
||||
@@ -62,18 +72,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
_loadedBullets.Push(entity);
|
||||
}
|
||||
_updateAppearance();
|
||||
}
|
||||
else if (_fillType != null)
|
||||
{
|
||||
// Load up bullets from fill.
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
var bullet = Owner.EntityManager.SpawnEntity(_fillType);
|
||||
AddBullet(bullet);
|
||||
}
|
||||
}
|
||||
|
||||
_updateAppearance();
|
||||
|
||||
OnAmmoCountChanged?.Invoke();
|
||||
_appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
|
||||
}
|
||||
@@ -113,6 +115,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
_appearance.SetData(BallisticMagazineVisuals.AmmoLeft, CountLoaded);
|
||||
}
|
||||
|
||||
void IMapInit.MapInit()
|
||||
{
|
||||
if (_fillType == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load up bullets from fill.
|
||||
for (var i = 0; i < Capacity; i++)
|
||||
{
|
||||
var bullet = Owner.EntityManager.SpawnEntity(_fillType);
|
||||
AddBullet(bullet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum BallisticMagazineType
|
||||
|
||||
@@ -6,31 +6,43 @@ using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy
|
||||
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy, IMapInit
|
||||
{
|
||||
public override string Name => "BallisticMagazineWeapon";
|
||||
|
||||
[ViewVariables]
|
||||
private string _defaultMagazine;
|
||||
|
||||
[ViewVariables]
|
||||
private ContainerSlot _magazineSlot;
|
||||
private BallisticMagazineType _magazineType;
|
||||
|
||||
[ViewVariables]
|
||||
public BallisticMagazineType MagazineType => _magazineType;
|
||||
[ViewVariables]
|
||||
private IEntity Magazine => _magazineSlot.ContainedEntity;
|
||||
|
||||
[ViewVariables]
|
||||
private Random _bulletDropRandom;
|
||||
[ViewVariables]
|
||||
private string _magInSound;
|
||||
[ViewVariables]
|
||||
private string _magOutSound;
|
||||
[ViewVariables]
|
||||
private string _autoEjectSound;
|
||||
[ViewVariables]
|
||||
private bool _autoEjectMagazine;
|
||||
[ViewVariables]
|
||||
private AppearanceComponent _appearance;
|
||||
|
||||
private static readonly Direction[] _randomBulletDirs =
|
||||
@@ -67,16 +79,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
_magazineSlot =
|
||||
ContainerManagerComponent.Ensure<ContainerSlot>("ballistic_gun_magazine", Owner,
|
||||
out var alreadyExisted);
|
||||
_magazineSlot = ContainerManagerComponent.Ensure<ContainerSlot>("ballistic_gun_magazine", Owner);
|
||||
|
||||
if (!alreadyExisted && _defaultMagazine != null)
|
||||
{
|
||||
var magazine = Owner.EntityManager.SpawnEntity(_defaultMagazine);
|
||||
InsertMagazine(magazine, false);
|
||||
}
|
||||
else if (Magazine != null)
|
||||
if (Magazine != null)
|
||||
{
|
||||
// Already got magazine from loading a container.
|
||||
Magazine.GetComponent<BallisticMagazineComponent>().OnAmmoCountChanged += _magazineAmmoCountChanged;
|
||||
@@ -262,5 +267,14 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
component.EjectMagazine();
|
||||
}
|
||||
}
|
||||
|
||||
void IMapInit.MapInit()
|
||||
{
|
||||
if (_defaultMagazine != null)
|
||||
{
|
||||
var magazine = Owner.EntityManager.SpawnEntity(_defaultMagazine);
|
||||
InsertMagazine(magazine, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user