Improves examine for ranged weapons, magazines and ammo.

This commit is contained in:
Víctor Aguilera Puerto
2020-08-22 20:07:35 +02:00
parent fffff53762
commit 5de139d6fd
6 changed files with 69 additions and 22 deletions

View File

@@ -16,11 +16,12 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
{
[RegisterComponent]
public sealed class AmmoBoxComponent : Component, IInteractUsing, IUse, IInteractHand, IMapInit
public sealed class AmmoBoxComponent : Component, IInteractUsing, IUse, IInteractHand, IMapInit, IExamine
{
public override string Name => "AmmoBox";
@@ -197,6 +198,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
return TryUse(eventArgs.User);
}
// So if you have 200 rounds in a box and that suddenly creates 200 entities you're not having a fun time
[Verb]
private sealed class DumpVerb : Verb<AmmoBoxComponent>
@@ -218,5 +221,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
component.EjectContents(10);
}
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
message.AddMarkup(Loc.GetString("\nIt's a [color=white]{0}[/color] ammo box.", _caliber));
message.AddMarkup(Loc.GetString("\nIt has [color=white]{0}[/color] out of [color=white]{1}[/color] ammo left.", AmmoLeft, _capacity));
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
@@ -8,6 +9,7 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -21,7 +23,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
/// Generally used for bullets but can be used for other things like bananas
/// </summary>
[RegisterComponent]
public class AmmoComponent : Component
public class AmmoComponent : Component, IExamine
{
public override string Name => "Ammo";
public BallisticCaliber Caliber => _caliber;
@@ -152,6 +154,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
};
EntitySystem.Get<EffectSystem>().CreateParticle(message);
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
var text = Loc.GetString("It's [color=white]{0}[/color] ammo.", Caliber);
message.AddMarkup(text);
}
}
public enum BallisticCaliber

View File

@@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
@@ -14,11 +15,12 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
{
[RegisterComponent]
public class RangedMagazineComponent : Component, IMapInit, IInteractUsing, IUse
public class RangedMagazineComponent : Component, IMapInit, IInteractUsing, IUse, IExamine
{
public override string Name => "RangedMagazine";
@@ -168,5 +170,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
return true;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
var text = Loc.GetString("It's a [color=white]{0}[/color] magazine of [color=white]{1}[/color] caliber.", MagazineType, Caliber);
message.AddMarkup(text);
}
}
}

View File

@@ -18,6 +18,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
@@ -25,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
/// Shotguns mostly
/// </summary>
[RegisterComponent]
public sealed class BoltActionBarrelComponent : ServerRangedBarrelComponent, IMapInit
public sealed class BoltActionBarrelComponent : ServerRangedBarrelComponent, IMapInit, IExamine
{
// Originally I had this logic shared with PumpBarrel and used a couple of variables to control things
// but it felt a lot messier to play around with, especially when adding verbs
@@ -297,6 +298,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
return TryInsertBullet(eventArgs.User, eventArgs.Using);
}
public override void Examine(FormattedMessage message, bool inDetailsRange)
{
base.Examine(message, inDetailsRange);
message.AddMarkup(Loc.GetString("\nIt uses [color=white]{0}[/color] ammo.", _caliber));
}
[Verb]
private sealed class OpenBoltVerb : Verb<BoltActionBarrelComponent>
{

View File

@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
using Content.Shared.GameObjects.Components.Weapons.Ranged.Barrels;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
@@ -15,6 +16,7 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
@@ -22,7 +24,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
/// Bolt-action rifles
/// </summary>
[RegisterComponent]
public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit
public sealed class PumpBarrelComponent : ServerRangedBarrelComponent, IMapInit, IExamine
{
public override string Name => "PumpBarrel";
@@ -211,5 +213,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
return TryInsertBullet(eventArgs);
}
public override void Examine(FormattedMessage message, bool inDetailsRange)
{
base.Examine(message, inDetailsRange);
message.AddMarkup(Loc.GetString("\nIt uses [color=white]{0}[/color] ammo.", _caliber));
}
}
}

View File

@@ -104,8 +104,20 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
serializer.DataReadWriteFunction(
"magazineTypes",
new List<MagazineType>(),
types => types.ForEach(mag => _magazineTypes |= mag),
() =>
types => types.ForEach(mag => _magazineTypes |= mag), GetMagazineTypes);
serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
serializer.DataField(ref _magFillPrototype, "magFillPrototype", null);
serializer.DataField(ref _autoEjectMag, "autoEjectMag", false);
serializer.DataField(ref _magNeedsOpenBolt, "magNeedsOpenBolt", false);
serializer.DataField(ref _soundBoltOpen, "soundBoltOpen", null);
serializer.DataField(ref _soundBoltClosed, "soundBoltClosed", null);
serializer.DataField(ref _soundRack, "soundRack", null);
serializer.DataField(ref _soundMagInsert, "soundMagInsert", null);
serializer.DataField(ref _soundMagEject, "soundMagEject", null);
serializer.DataField(ref _soundAutoEject, "soundAutoEject", "/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
}
private List<MagazineType> GetMagazineTypes()
{
var types = new List<MagazineType>();
@@ -118,17 +130,6 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
}
return types;
});
serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
serializer.DataField(ref _magFillPrototype, "magFillPrototype", null);
serializer.DataField(ref _autoEjectMag, "autoEjectMag", false);
serializer.DataField(ref _magNeedsOpenBolt, "magNeedsOpenBolt", false);
serializer.DataField(ref _soundBoltOpen, "soundBoltOpen", null);
serializer.DataField(ref _soundBoltClosed, "soundBoltClosed", null);
serializer.DataField(ref _soundRack, "soundRack", null);
serializer.DataField(ref _soundMagInsert, "soundMagInsert", null);
serializer.DataField(ref _soundMagEject, "soundMagEject", null);
serializer.DataField(ref _soundAutoEject, "soundAutoEject", "/Audio/Weapons/Guns/EmptyAlarm/smg_empty_alarm.ogg");
}
public override ComponentState GetComponentState()
@@ -420,8 +421,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
base.Examine(message, inDetailsRange);
var text = Loc.GetString("\nIt uses {0} ammo.", Caliber);
message.AddText(text);
message.AddMarkup(Loc.GetString("\nIt uses [color=white]{0}[/color] ammo.", Caliber));
foreach (var magazineType in GetMagazineTypes())
{
message.AddMarkup(Loc.GetString("\nIt accepts [color=white]{0}[/color] magazines.", magazineType));
}
}
[Verb]