Vending Machine Abuse (#8863)
* piece of shit i'll abuse your vending ass * placeholder * Update types.yml * threshold
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.VendingMachines;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -26,6 +27,16 @@ namespace Content.Server.VendingMachines
|
||||
[DataField("speedLimiter")]
|
||||
public bool CanShoot = false;
|
||||
|
||||
/// <summary>
|
||||
/// The chance that a vending machine will randomly dispense an item on hit.
|
||||
/// Chance is 0 if null.
|
||||
/// </summary>
|
||||
[DataField("dispenseOnHitChance")]
|
||||
public float? DispenseOnHitChance;
|
||||
|
||||
[DataField("dispenseOnHitThreshold")]
|
||||
public float? DispenseOnHitThreshold;
|
||||
|
||||
[DataField("soundVend")]
|
||||
// Grabbed from: https://github.com/discordia-space/CEV-Eris/blob/f702afa271136d093ddeb415423240a2ceb212f0/sound/machines/vending_drop.ogg
|
||||
public SoundSpecifier SoundVend = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg");
|
||||
@@ -34,6 +45,9 @@ namespace Content.Server.VendingMachines
|
||||
// Yoinked from: https://github.com/discordia-space/CEV-Eris/blob/35bbad6764b14e15c03a816e3e89aa1751660ba9/sound/machines/Custom_deny.ogg
|
||||
public SoundSpecifier SoundDeny = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
|
||||
|
||||
[DataField("action", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
|
||||
public string? Action = "VendingThrow";
|
||||
|
||||
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(VendingMachineUiKey.Key);
|
||||
|
||||
public float NonLimitedEjectForce = 7.5f;
|
||||
|
||||
@@ -4,6 +4,9 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Destructible;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Throwing;
|
||||
@@ -24,6 +27,7 @@ namespace Content.Server.VendingMachines
|
||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _action = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -34,6 +38,9 @@ namespace Content.Server.VendingMachines
|
||||
SubscribeLocalEvent<VendingMachineComponent, VendingMachineEjectMessage>(OnInventoryEjectMessage);
|
||||
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
|
||||
SubscribeLocalEvent<VendingMachineComponent, GotEmaggedEvent>(OnEmagged);
|
||||
SubscribeLocalEvent<VendingMachineComponent, DamageChangedEvent>(OnDamage);
|
||||
|
||||
SubscribeLocalEvent<VendingMachineComponent, VendingMachineSelfDispenseEvent>(OnSelfDispense);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, VendingMachineComponent component, ComponentInit args)
|
||||
@@ -45,6 +52,12 @@ namespace Content.Server.VendingMachines
|
||||
TryUpdateVisualState(uid, null, component);
|
||||
}
|
||||
|
||||
if (component.Action != null)
|
||||
{
|
||||
var action = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(component.Action));
|
||||
_action.AddAction(uid, action, uid);
|
||||
}
|
||||
|
||||
InitializeFromPrototype(uid, component);
|
||||
}
|
||||
|
||||
@@ -91,6 +104,24 @@ namespace Content.Server.VendingMachines
|
||||
component.Emagged = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnDamage(EntityUid uid, VendingMachineComponent component, DamageChangedEvent args)
|
||||
{
|
||||
if (component.DispenseOnHitChance == null || args.DamageDelta == null)
|
||||
return;
|
||||
|
||||
if (args.DamageDelta.Total >= component.DispenseOnHitThreshold && _random.Prob(component.DispenseOnHitChance.Value))
|
||||
EjectRandom(uid, true, component);
|
||||
}
|
||||
|
||||
private void OnSelfDispense(EntityUid uid, VendingMachineComponent component, VendingMachineSelfDispenseEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
EjectRandom(uid, true, component);
|
||||
}
|
||||
|
||||
public void InitializeFromPrototype(EntityUid uid, VendingMachineComponent? vendComponent = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user