Item status!
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -20,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
/// Component that represents a handheld lightsource which can be toggled on and off.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
internal class HandheldLightComponent : Component, IUse, IExamine, IAttackBy, IMapInit
|
||||
internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IAttackBy, IMapInit
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ISharedNotifyManager _notifyManager;
|
||||
@@ -44,9 +45,6 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string Name => "HandheldLight";
|
||||
|
||||
/// <summary>
|
||||
/// Status of light, whether or not it is emitting light.
|
||||
@@ -73,7 +71,6 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message)
|
||||
@@ -153,6 +150,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
soundComponent.Play("/Audio/machines/button.ogg");
|
||||
}
|
||||
|
||||
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Cell missing..."));
|
||||
return;
|
||||
}
|
||||
@@ -166,6 +164,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
soundComponent.Play("/Audio/machines/button.ogg");
|
||||
}
|
||||
|
||||
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
|
||||
return;
|
||||
}
|
||||
@@ -195,6 +194,8 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
|
||||
var cell = Cell;
|
||||
if (cell == null || !cell.TryDeductWattage(Wattage, frameTime)) TurnOff();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
private void EjectCell(IEntity user)
|
||||
@@ -227,6 +228,23 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
if (Cell == null)
|
||||
{
|
||||
return new HandheldLightComponentState(null);
|
||||
}
|
||||
|
||||
if (Cell.AvailableCharge(1) < Wattage)
|
||||
{
|
||||
// Practically zero.
|
||||
// This is so the item status works correctly.
|
||||
return new HandheldLightComponentState(0);
|
||||
}
|
||||
|
||||
return new HandheldLightComponentState(Cell.Charge / Cell.Capacity);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
public sealed class EjectCellVerb : Verb<HandheldLightComponent>
|
||||
{
|
||||
@@ -252,6 +270,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper", Owner.Transform.GridPosition);
|
||||
_cellContainer.Insert(cell);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -32,6 +34,7 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "Welder";
|
||||
public override uint? NetID => ContentNetIDs.WELDER;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum fuel capacity the welder can hold
|
||||
@@ -40,8 +43,13 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
public float FuelCapacity
|
||||
{
|
||||
get => _fuelCapacity;
|
||||
set => _fuelCapacity = value;
|
||||
set
|
||||
{
|
||||
_fuelCapacity = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
private float _fuelCapacity = 50;
|
||||
|
||||
/// <summary>
|
||||
@@ -51,9 +59,15 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
public float Fuel
|
||||
{
|
||||
get => _fuel;
|
||||
set => _fuel = value;
|
||||
set
|
||||
{
|
||||
_fuel = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
private float _fuel = 0;
|
||||
private bool _activated = false;
|
||||
|
||||
/// <summary>
|
||||
/// Default Cost of using the welder fuel for an action
|
||||
@@ -69,7 +83,15 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
/// Status of welder, whether it is ignited
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool Activated { get; private set; } = false;
|
||||
public bool Activated
|
||||
{
|
||||
get => _activated;
|
||||
private set
|
||||
{
|
||||
_activated = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
//private string OnSprite { get; set; }
|
||||
//private string OffSprite { get; set; }
|
||||
@@ -87,6 +109,7 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
|
||||
serializer.DataField(ref _fuelCapacity, "Capacity", 50);
|
||||
serializer.DataField(ref _fuel, "Fuel", FuelCapacity);
|
||||
serializer.DataField(ref _activated, "Activated", false);
|
||||
}
|
||||
|
||||
public void OnUpdate(float frameTime)
|
||||
@@ -185,5 +208,10 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
|
||||
_entitySystemManager.GetEntitySystem<AudioSystem>()
|
||||
.Play(file, AudioParams.Default.WithVolume(volume));
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new WelderComponentState(FuelCapacity, Fuel, Activated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
@@ -16,7 +17,7 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
|
||||
// TODO: Naming and presentation and such could use some improvement.
|
||||
[RegisterComponent]
|
||||
public class StackComponent : Component, IAttackBy, IExamine
|
||||
public class StackComponent : SharedStackComponent, IAttackBy, IExamine
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ISharedNotifyManager _sharedNotifyManager;
|
||||
@@ -26,8 +27,6 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
private int _count = 50;
|
||||
private int _maxCount = 50;
|
||||
|
||||
public override string Name => "Stack";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Count
|
||||
{
|
||||
@@ -39,11 +38,20 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
{
|
||||
Owner.Delete();
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public int MaxCount { get => _maxCount; private set => _maxCount = value; }
|
||||
public int MaxCount
|
||||
{
|
||||
get => _maxCount;
|
||||
private set
|
||||
{
|
||||
_maxCount = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public int AvailableSpace => MaxCount - Count;
|
||||
@@ -155,6 +163,11 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
"There is [color=lightgray]1[/color] thing in the stack",
|
||||
"There are [color=lightgray]{0}[/color] things in the stack.", Count, Count));
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new StackComponentState(Count, MaxCount);
|
||||
}
|
||||
}
|
||||
|
||||
public enum StackType
|
||||
|
||||
@@ -24,33 +24,27 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
[RegisterComponent]
|
||||
public class BallisticMagazineWeaponComponent : BallisticWeaponComponent, IUse, IAttackBy, IMapInit
|
||||
{
|
||||
private const float BulletOffset = 0.2f;
|
||||
|
||||
public override string Name => "BallisticMagazineWeapon";
|
||||
public override uint? NetID => ContentNetIDs.BALLISTIC_MAGAZINE_WEAPON;
|
||||
|
||||
[ViewVariables]
|
||||
private string _defaultMagazine;
|
||||
[ViewVariables] private string _defaultMagazine;
|
||||
|
||||
[ViewVariables]
|
||||
private ContainerSlot _magazineSlot;
|
||||
[ViewVariables] private ContainerSlot _magazineSlot;
|
||||
private List<BallisticMagazineType> _magazineTypes;
|
||||
|
||||
[ViewVariables]
|
||||
public List<BallisticMagazineType> MagazineTypes => _magazineTypes;
|
||||
[ViewVariables]
|
||||
private IEntity Magazine => _magazineSlot.ContainedEntity;
|
||||
[ViewVariables] public List<BallisticMagazineType> MagazineTypes => _magazineTypes;
|
||||
[ViewVariables] private IEntity Magazine => _magazineSlot.ContainedEntity;
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRobustRandom _bulletDropRandom;
|
||||
#pragma warning restore 649
|
||||
[ViewVariables]
|
||||
private string _magInSound;
|
||||
[ViewVariables]
|
||||
private string _magOutSound;
|
||||
[ViewVariables]
|
||||
private string _autoEjectSound;
|
||||
[ViewVariables]
|
||||
private bool _autoEjectMagazine;
|
||||
[ViewVariables]
|
||||
private AppearanceComponent _appearance;
|
||||
[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,7 +61,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _magazineTypes, "magazines",
|
||||
new List<BallisticMagazineType>{BallisticMagazineType.Unspecified});
|
||||
new List<BallisticMagazineType> {BallisticMagazineType.Unspecified});
|
||||
serializer.DataField(ref _defaultMagazine, "default_magazine", null);
|
||||
serializer.DataField(ref _autoEjectMagazine, "auto_eject_magazine", false);
|
||||
serializer.DataField(ref _autoEjectSound, "sound_auto_eject", null);
|
||||
@@ -137,6 +131,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
}
|
||||
|
||||
_updateAppearance();
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -153,15 +148,17 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
entity.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
if (_magOutSound != null)
|
||||
{
|
||||
Owner.GetComponent<SoundComponent>().Play(_magOutSound);
|
||||
Owner.GetComponent<SoundComponent>().Play(_magOutSound, AudioParams.Default.WithVolume(20));
|
||||
}
|
||||
|
||||
_updateAppearance();
|
||||
Dirty();
|
||||
entity.GetComponent<BallisticMagazineComponent>().OnAmmoCountChanged -= _magazineAmmoCountChanged;
|
||||
return true;
|
||||
}
|
||||
|
||||
_updateAppearance();
|
||||
Dirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,7 +168,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
|
||||
// Eject chambered bullet.
|
||||
var entity = RemoveFromChamber(chamber);
|
||||
entity.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
var offsetPos = (CalcBulletOffset(), CalcBulletOffset());
|
||||
entity.Transform.GridPosition = Owner.Transform.GridPosition.Offset(offsetPos);
|
||||
entity.Transform.LocalRotation = _bulletDropRandom.Pick(_randomBulletDirs).ToAngle();
|
||||
var effect = $"/Audio/Guns/Casings/casingfall{_bulletDropRandom.Next(1, 4)}.ogg";
|
||||
Owner.GetComponent<SoundComponent>().Play(effect, AudioParams.Default.WithVolume(-3));
|
||||
@@ -187,17 +185,31 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
|
||||
if (magComponent.CountLoaded == 0 && _autoEjectMagazine)
|
||||
{
|
||||
EjectMagazine();
|
||||
if (_autoEjectSound != null)
|
||||
{
|
||||
Owner.GetComponent<SoundComponent>().Play(_autoEjectSound, AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
DoAutoEject();
|
||||
}
|
||||
}
|
||||
|
||||
Dirty();
|
||||
_updateAppearance();
|
||||
}
|
||||
|
||||
private float CalcBulletOffset()
|
||||
{
|
||||
return _bulletDropRandom.NextFloat() * (BulletOffset * 2) - BulletOffset;
|
||||
}
|
||||
|
||||
private void DoAutoEject()
|
||||
{
|
||||
SendNetworkMessage(new BmwComponentAutoEjectedMessage());
|
||||
EjectMagazine();
|
||||
if (_autoEjectSound != null)
|
||||
{
|
||||
Owner.GetComponent<SoundComponent>().Play(_autoEjectSound, AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
var ret = EjectMagazine();
|
||||
@@ -237,6 +249,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
|
||||
private void _magazineAmmoCountChanged()
|
||||
{
|
||||
Dirty();
|
||||
_updateAppearance();
|
||||
}
|
||||
|
||||
@@ -257,6 +270,21 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Projectile
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
var chambered = GetChambered(0) != null;
|
||||
|
||||
(int, int)? count = null;
|
||||
|
||||
if (Magazine != null)
|
||||
{
|
||||
var magComponent = Magazine.GetComponent<BallisticMagazineComponent>();
|
||||
count = (magComponent.CountLoaded, magComponent.Capacity);
|
||||
}
|
||||
|
||||
return new BallisticMagazineWeaponComponentState(chambered, count);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
public sealed class EjectMagazineVerb : Verb<BallisticMagazineWeaponComponent>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user