Add snatcherprod (#422)

This commit is contained in:
Aviu00
2023-09-21 23:04:05 +09:00
committed by Aviu00
parent c3236f829c
commit 0cc831cb18
18 changed files with 355 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Prying.Systems;
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Stacks;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using Robust.Shared.Containers;
@@ -92,6 +93,9 @@ namespace Content.Server.Construction
if (!Resolve(uid, ref construction))
return HandleResult.False;
if (TryComp(uid, out StackComponent? stack) && stack.Count > 1) // WD
return HandleResult.False;
// Let's make extra sure this is zero...
construction.StepIndex = 0;

View File

@@ -0,0 +1,9 @@
namespace Content.Server.White.Snatcherprod;
[RegisterComponent, Access(typeof(SnatcherprodSystem))]
public sealed partial class SnatcherprodComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("energyPerUse")]
public float EnergyPerUse { get; set; } = 36;
}

View File

@@ -0,0 +1,178 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Damage.Events;
using Content.Shared.Examine;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Toggleable;
using Robust.Shared.Containers;
namespace Content.Server.White.Snatcherprod;
public sealed class SnatcherprodSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedContainerSystem _containers = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedItemToggleSystem _itemToggle = default!;
private const string CellSlot = "cell_slot";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SnatcherprodComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<SnatcherprodComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
SubscribeLocalEvent<SnatcherprodComponent, StaminaMeleeHitEvent>(OnHit);
SubscribeLocalEvent<SnatcherprodComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
SubscribeLocalEvent<SnatcherprodComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
SubscribeLocalEvent<SnatcherprodComponent, ItemToggleActivateAttemptEvent>(TryTurnOn);
SubscribeLocalEvent<SnatcherprodComponent, ItemToggledEvent>(ToggleDone);
}
private void OnEntInserted(EntityUid uid, SnatcherprodComponent component, EntInsertedIntoContainerMessage args)
{
_itemToggle.TryDeactivate(uid, predicted: false);
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
_appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance);
}
}
private void OnEntRemoved(EntityUid uid, SnatcherprodComponent component, EntRemovedFromContainerMessage args)
{
if (TerminatingOrDeleted(uid))
return;
if (!_itemToggle.IsActivated(uid))
{
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
_appearance.SetData(uid, ToggleVisuals.Toggled, "nocell", appearance);
}
}
else
_itemToggle.TryDeactivate(uid, predicted: false);
}
private void OnHit(EntityUid uid, SnatcherprodComponent component, StaminaMeleeHitEvent args)
{
if (!_itemToggle.IsActivated(uid) || args.HitList.Count == 0)
return;
var entity = args.HitList.First().Entity;
if (!TryComp(entity, out HandsComponent? hands))
return;
EntityUid? heldEntity = null;
if (hands.ActiveHandEntity != null)
heldEntity = hands.ActiveHandEntity;
else
{
foreach (var hand in hands.Hands)
{
if (hand.Value.HeldEntity == null)
continue;
heldEntity = hand.Value.HeldEntity;
break;
}
if (heldEntity == null)
return;
}
if (!_hands.TryDrop(entity, heldEntity.Value, null, false, false, handsComp: hands))
return;
_hands.PickupOrDrop(args.User, heldEntity.Value, false);
}
private void OnStaminaHitAttempt(EntityUid uid, SnatcherprodComponent component, ref StaminaDamageOnHitAttemptEvent args)
{
if (!_itemToggle.IsActivated(uid) || !TryGetBatteryComponent(uid, out var battery, out var batteryUid) ||
!_battery.TryUseCharge(batteryUid.Value, component.EnergyPerUse, battery))
{
args.Cancelled = true;
return;
}
if (battery.CurrentCharge < component.EnergyPerUse)
{
_itemToggle.TryDeactivate(uid, predicted: false);
}
}
private void OnExamined(EntityUid uid, SnatcherprodComponent comp, ExaminedEvent args)
{
var msg = _itemToggle.IsActivated(uid)
? Loc.GetString("comp-snatcherprod-examined-on")
: Loc.GetString("comp-snatcherprod-examined-off");
args.PushMarkup(msg);
}
private void ToggleDone(Entity<SnatcherprodComponent> entity, ref ItemToggledEvent args)
{
if (TryGetBatteryComponent(entity, out _, out _) || !TryComp<AppearanceComponent>(entity, out var appearance))
return;
_appearance.SetData(entity, ToggleVisuals.Toggled, "nocell", appearance);
}
private void TryTurnOn(Entity<SnatcherprodComponent> entity, ref ItemToggleActivateAttemptEvent args)
{
if (TryGetBatteryComponent(entity, out var battery, out _) &&
battery.CurrentCharge >= entity.Comp.EnergyPerUse)
return;
args.Cancelled = true;
if (TryComp<AppearanceComponent>(entity, out var appearance))
{
_appearance.SetData(entity, ToggleVisuals.Toggled, battery == null ? "nocell" : false, appearance);
}
if (args.User != null)
{
_popup.PopupEntity(Loc.GetString("stunbaton-component-low-charge"), (EntityUid) args.User,
(EntityUid) args.User);
}
}
private bool TryGetBatteryComponent(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? battery,
[NotNullWhen(true)] out EntityUid? batteryUid)
{
if (TryComp(uid, out battery))
{
batteryUid = uid;
return true;
}
if (!_containers.TryGetContainer(uid, CellSlot, out var container) ||
container is not ContainerSlot slot)
{
battery = null;
batteryUid = null;
return false;
}
batteryUid = slot.ContainedEntity;
if (batteryUid != null)
return TryComp(batteryUid, out battery);
battery = null;
return false;
}
}

View File

@@ -24,8 +24,11 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
/// </summary>
public float FlatModifier = 0;
public StaminaMeleeHitEvent(List<(EntityUid Entity, StaminaComponent Component)> hitList)
public EntityUid User; // WD
public StaminaMeleeHitEvent(List<(EntityUid Entity, StaminaComponent Component)> hitList, EntityUid user) // WD EDIT
{
HitList = hitList;
User = user; // WD
}
}

View File

@@ -169,7 +169,7 @@ public sealed partial class StaminaSystem : EntitySystem
toHit.Add((ent, stam));
}
var hitEvent = new StaminaMeleeHitEvent(toHit);
var hitEvent = new StaminaMeleeHitEvent(toHit, args.User); // WD EDIT
RaiseLocalEvent(uid, hitEvent);
if (hitEvent.Handled)

View File

@@ -0,0 +1,2 @@
comp-snatcherprod-examined-on = Хваталка [color=darkgreen]включена[/color].
comp-snatcherprod-examined-off = Хваталка [color=darkred]выключена[/color].

View File

@@ -127,6 +127,10 @@
- ItemMask
restitution: 0.3
friction: 0.2
- type: Construction
deconstructionTarget: null
graph: SnatcherprodGraph
node: rod
- type: entity
parent: PartRodMetal

View File

@@ -1,4 +1,4 @@
- type: entity
- type: entity
id: BaseStockPart
name: stock part
parent: BaseItem

View File

@@ -0,0 +1,77 @@
- type: entity
name: хваталка
parent: BaseItem
id: Snatcherprod
description: Искрится жаждой воровства и коварства.
components:
- type: Sprite
sprite: White/Objects/Weapons/snatcherprod.rsi
layers:
- state: snatcherprod_nocell
map: [ "enum.ToggleVisuals.Layer" ]
- type: ItemToggle
soundActivate:
collection: sparks
params:
variation: 0.250
soundDeactivate:
collection: sparks
params:
variation: 0.250
soundFailToActivate:
path: /Audio/Machines/button.ogg
params:
variation: 0.250
- type: ItemToggleMeleeWeapon
activatedDamage:
types:
Blunt: 0
- type: MeleeWeapon
damage:
types:
Blunt: 9
angle: 0
animation: WeaponArcThrust
- type: StaminaDamageOnHit
damage: 40
sound: /Audio/Weapons/egloves.ogg
- type: StaminaDamageOnCollide
damage: 20
- type: UseDelay
- type: Item
size: Normal
- type: Appearance
- type: GenericVisualizer
visuals:
enum.ToggleVisuals.Toggled:
enum.ToggleVisuals.Layer:
nocell: {state: snatcherprod_nocell}
True: {state: snatcherprod_on}
False: {state: snatcherprod_off}
- type: PowerCellSlot
cellSlotId: cell_slot
- type: ItemSlots
slots:
cell_slot:
name: power-cell-slot-component-slot-name-default
- type: Snatcherprod
- type: Construction
deconstructionTarget: null
graph: SnatcherprodGraph
node: snatcherprod
- type: entity
name: палка
parent: BaseItem
id: ProdUnfinished
description: Стержень с проводами.
components:
- type: Sprite
sprite: White/Objects/Weapons/prod.rsi
state: prod_unfinished
- type: Item
size: 30
- type: Construction
deconstructionTarget: null
graph: SnatcherprodGraph
node: unfinished

View File

@@ -95,3 +95,30 @@
doAfter: 1
- node: crossbow
entity: WeaponPoweredCrossbow
- type: constructionGraph
id: SnatcherprodGraph
start: rod
graph:
- node: rod
entity: PartRodMetal1
edges:
- to: unfinished
steps:
- material: Cable
amount: 15
doAfter: 1
- node: unfinished
entity: ProdUnfinished
edges:
- to: capacitor
steps:
- tag: CapacitorStockPart
- node: capacitor
edges:
- to: snatcherprod
steps:
- material: Telecrystal
traitorOnly: true
- node: snatcherprod
entity: Snatcherprod

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from tgstation at https://github.com/tgstation/ at d0dffe7ca643db2624424fdcebf45863f85c0448",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "prod_unfinished"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

View File

@@ -0,0 +1,34 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from tgstation at https://github.com/tgstation/ at d0dffe7ca643db2624424fdcebf45863f85c0448",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "snatcherprod_off"
},
{
"name": "snatcherprod_nocell"
},
{
"name": "snatcherprod_on",
"delays": [
[
0.1,
0.1
]
]
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B