Fix being able to use invalid verbs as a ghost (#1157)

* Add CanInteract check to 18 verbs

* Add more caninteract checks to verbs without it

Storage toggle open, ammo box dump, bolt open and close, revolver spin and magazine open and close
This commit is contained in:
DrSmugleaf
2020-06-22 18:54:56 +02:00
committed by GitHub
parent 6fe7d11d54
commit ff0f082138
16 changed files with 192 additions and 68 deletions

View File

@@ -252,6 +252,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
{
protected override void GetData(IEntity user, StunbatonComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
if (component.Cell == null)
{
data.Text = "Eject cell (cell missing)";

View File

@@ -63,9 +63,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
_ammoContainer.Insert(entity);
}
}
}
void IMapInit.MapInit()
{
_unspawnedCount += _capacity;
@@ -117,7 +117,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
Owner.PopupMessage(user, Loc.GetString("No room"));
return false;
}
_spawnedAmmo.Push(entity);
_ammoContainer.Insert(entity);
UpdateAppearance();
@@ -136,7 +136,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
for (var i = 0; i < Math.Max(10, rangedMagazine.ShotsLeft); i++)
{
var ammo = rangedMagazine.TakeAmmo();
if (!TryInsertAmmo(eventArgs.User, ammo))
{
rangedMagazine.TryInsertAmmo(eventArgs.User, ammo);
@@ -146,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
return true;
}
return false;
}
@@ -175,7 +175,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
{
var ejectCount = Math.Min(count, Capacity);
var ejectAmmo = new List<IEntity>(ejectCount);
for (var i = 0; i < Math.Min(count, Capacity); i++)
{
var ammo = TakeAmmo();
@@ -200,13 +200,19 @@ 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>
{
protected override void GetData(IEntity user, AmmoBoxComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Dump 10");
data.Visibility = component.AmmoLeft > 0 ? VerbVisibility.Visible : VerbVisibility.Disabled;
}
@@ -217,4 +223,4 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition
}
}
}
}
}

View File

@@ -28,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
// 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
public override string Name => "BoltActionBarrel";
public override int ShotsLeft
@@ -62,7 +62,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
}
var soundSystem = EntitySystem.Get<AudioSystem>();
if (value)
{
if (_soundBoltOpen != null)
@@ -77,7 +77,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
soundSystem.PlayAtCoords(_soundBoltClosed, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
}
}
_boltOpen = value;
UpdateAppearance();
}
@@ -105,7 +105,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
serializer.DataField(ref _soundBoltClosed, "soundBoltClosed", "/Audio/Guns/Bolt/rifle_bolt_closed.ogg");
serializer.DataField(ref _soundInsert, "soundInsert", "/Audio/Guns/MagIn/bullet_insert.ogg");
}
void IMapInit.MapInit()
{
if (_fillPrototype != null)
@@ -137,7 +137,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
_appearanceComponent = appearanceComponent;
}
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, true);
UpdateAppearance();
}
@@ -183,7 +183,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
var ammoComponent = chamberedEntity.GetComponent<AmmoComponent>();
if (!ammoComponent.Caseless)
{
EjectCasing(chamberedEntity);
EjectCasing(chamberedEntity);
}
}
@@ -216,7 +216,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundCycle, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
}
}
Dirty();
UpdateAppearance();
}
@@ -264,9 +264,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
UpdateAppearance();
return true;
}
Owner.PopupMessage(user, Loc.GetString("No room"));
return false;
}
@@ -279,7 +279,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
// Dirty();
return true;
}
Cycle(true);
return true;
}
@@ -288,12 +288,18 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
return TryInsertBullet(eventArgs.User, eventArgs.Using);
}
[Verb]
private sealed class OpenBoltVerb : Verb<BoltActionBarrelComponent>
{
protected override void GetData(IEntity user, BoltActionBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Open bolt");
data.Visibility = component.BoltOpen ? VerbVisibility.Disabled : VerbVisibility.Visible;
}
@@ -303,12 +309,18 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
component.BoltOpen = true;
}
}
[Verb]
private sealed class CloseBoltVerb : Verb<BoltActionBarrelComponent>
{
protected override void GetData(IEntity user, BoltActionBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Close bolt");
data.Visibility = component.BoltOpen ? VerbVisibility.Visible : VerbVisibility.Disabled;
}
@@ -319,4 +331,4 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
}
}
}
}
}

View File

@@ -221,6 +221,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
protected override void GetData(IEntity user, RevolverBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Spin");
if (component.Capacity <= 1)
{

View File

@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
public override string Name => "MagazineBarrel";
public override uint? NetID => ContentNetIDs.MAGAZINE_BARREL;
private ContainerSlot _chamberContainer;
[ViewVariables] public bool HasMagazine => _magazineContainer.ContainedEntity != null;
private ContainerSlot _magazineContainer;
@@ -118,11 +118,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity);
}
return new MagazineBarrelComponentState(
_chamberContainer.ContainedEntity != null,
FireRateSelector,
count,
_chamberContainer.ContainedEntity != null,
FireRateSelector,
count,
SoundGunshot);
}
@@ -134,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
_appearanceComponent = appearanceComponent;
}
_chamberContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-chamber", Owner);
_magazineContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-magazine", Owner);
}
@@ -194,7 +194,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
var ammoComponent = chamberEntity.GetComponent<AmmoComponent>();
if (!ammoComponent.Caseless)
{
EjectCasing(chamberEntity);
EjectCasing(chamberEntity);
}
}
@@ -207,7 +207,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
// If you're really into gunporn you could put a sound here
_chamberContainer.Insert(nextRound);
}
var soundSystem = EntitySystem.Get<AudioSystem>();
if (_autoEjectMag && magazine != null && magazine.GetComponent<RangedMagazineComponent>().ShotsLeft == 0)
@@ -245,7 +245,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
soundSystem.PlayAtCoords(_soundRack, Owner.Transform.GridPosition, AudioParams.Default.WithVolume(-2));
}
}
Dirty();
UpdateAppearance();
}
@@ -310,7 +310,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{
handsComponent.PutInHandOrDrop(mag.GetComponent<ItemComponent>());
}
Dirty();
UpdateAppearance();
}
@@ -385,12 +385,18 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
return false;
}
[Verb]
private sealed class EjectMagazineVerb : Verb<ServerMagazineBarrelComponent>
{
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Eject magazine");
if (component.MagNeedsOpenBolt)
{
@@ -408,12 +414,18 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
component.RemoveMagazine(user);
}
}
[Verb]
private sealed class OpenBoltVerb : Verb<ServerMagazineBarrelComponent>
{
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Open bolt");
data.Visibility = component.BoltOpen ? VerbVisibility.Disabled : VerbVisibility.Visible;
}
@@ -423,12 +435,18 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
component.ToggleBolt();
}
}
[Verb]
private sealed class CloseBoltVerb : Verb<ServerMagazineBarrelComponent>
{
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Close bolt");
data.Visibility = component.BoltOpen ? VerbVisibility.Visible : VerbVisibility.Disabled;
}