Adds sized (S, M, L) power cells and a generic component for battery powered items (#2352)

* Refactor battery/powercell assets and add new ones.

* committing before I fuck things up

* slot component doned I think

* dictionary update

* Fixes

* Moving flashlight to powerslotcomponent

* har har i am using the message tubes

* Better documentation comment

* Reverting this overengineered garbage.

* Off with ye I said

* Examine texts.

* Some minor fixes to IDE complaints

* slot size from yaml

* Ignored component + removing a useless typo entry

* Making stunbatons use this

* Handle the message and remove some unnecessary dirtiness

* actionblocker checks

* remove unused file

* remove updatevisual

* make these nullable

* make these nullable too

* Unrename sprite folder

* check itemcomponent on insertion

* Use SendMessage over Owner.SendMessage

* Add support for auto-recharging batteries, an auto-recharging cell, and make flashlight status update correctly if one is inserted in it.

* get rid of public fields which are Bad

* add a description for the stun baton while i'm in here

* one more public field

* Add the blinky animation to the atomic cell

* Fix the charge indicator being STUPID

* better comments

* this is a better function

* add pause for flashlight, remove unnecessary imports from battery

* potato battery copyright link

* WHO DID THAT

* mr clean has come

* Random pitch

* pausing

* round to nearest levels
This commit is contained in:
Peter Wedder
2020-10-29 20:17:03 +02:00
committed by GitHub
parent 60bee860cb
commit fca556a1c1
81 changed files with 1328 additions and 284 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
@@ -28,7 +29,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class StunbatonComponent : MeleeWeaponComponent, IUse, IExamine, IMapInit, IInteractUsing, IThrowCollide
public class StunbatonComponent : MeleeWeaponComponent, IUse, IExamine, IInteractUsing, IThrowCollide
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
@@ -36,7 +37,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
private bool _activated = false;
[ViewVariables] private ContainerSlot _cellContainer;
[ViewVariables] private PowerCellSlotComponent _cellSlot = default!;
private PowerCellComponent? Cell => _cellSlot.Cell;
[ViewVariables(VVAccess.ReadWrite)]
private float _paralyzeChanceNoSlowdown = 0.35f;
@@ -55,23 +57,10 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
[ViewVariables]
public bool Activated => _activated;
[ViewVariables]
private BatteryComponent Cell
{
get
{
if (_cellContainer.ContainedEntity == null) return null;
_cellContainer.ContainedEntity.TryGetComponent(out BatteryComponent cell);
return cell;
}
}
public override void Initialize()
{
base.Initialize();
_cellContainer =
ContainerManagerComponent.Ensure<ContainerSlot>("stunbaton_cell_container", Owner, out var existed);
_cellSlot = Owner.EnsureComponent<PowerCellSlotComponent>();
}
public override void ExposeData(ObjectSerializer serializer)
@@ -84,6 +73,23 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
serializer.DataField(ref _slowdownTime, "slowdownTime", 5f);
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PowerCellChangedMessage m:
if (component is PowerCellSlotComponent slotComponent && slotComponent == _cellSlot)
{
if (m.Ejected)
{
TurnOff();
}
}
break;
}
}
protected override bool OnHitEntities(IReadOnlyList<IEntity> entities, AttackEventArgs eventArgs)
{
if (!Activated || entities.Count == 0 || Cell == null)
@@ -96,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
foreach (var entity in entities)
{
if (!entity.TryGetComponent(out StunnableComponent stunnable)) continue;
if (!entity.TryGetComponent(out StunnableComponent? stunnable)) continue;
if(!stunnable.SlowedDown)
if(_robustRandom.Prob(_paralyzeChanceNoSlowdown))
@@ -120,6 +126,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
private bool ToggleStatus(IEntity user)
{
if (!ActionBlockerSystem.CanUse(user)) return false;
if (Activated)
{
TurnOff();
@@ -158,9 +165,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
var sprite = Owner.GetComponent<SpriteComponent>();
var item = Owner.GetComponent<ItemComponent>();
var cell = Cell;
if (cell == null)
if (Cell == null)
{
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
@@ -168,7 +174,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
return;
}
if (cell.CurrentCharge < EnergyPerUse)
if (Cell.CurrentCharge < EnergyPerUse)
{
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
Owner.PopupMessage(user, Loc.GetString("Dead cell..."));
@@ -191,51 +197,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!eventArgs.Using.HasComponent<BatteryComponent>()) return false;
if (Cell != null) return false;
var handsComponent = eventArgs.User.GetComponent<IHandsComponent>();
if (!handsComponent.Drop(eventArgs.Using, _cellContainer))
{
return false;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/pistol_magin.ogg", Owner);
if (!ActionBlockerSystem.CanInteract(eventArgs.User)) return false;
if (!_cellSlot.InsertCell(eventArgs.Using)) return false;
Dirty();
return true;
}
private void EjectCell(IEntity user)
{
if (Cell == null)
{
return;
}
var cell = Cell;
if (!_cellContainer.Remove(cell.Owner))
{
return;
}
if (!user.TryGetComponent(out HandsComponent hands))
{
return;
}
if (!hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
{
cell.Owner.Transform.Coordinates = user.Transform.Coordinates;
}
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Items/pistol_magout.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (Activated)
@@ -244,48 +211,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
}
}
public void MapInit()
{
if (_cellContainer.ContainedEntity != null)
{
return;
}
var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper", Owner.Transform.Coordinates);
_cellContainer.Insert(cell);
}
[Verb]
public sealed class EjectCellVerb : Verb<StunbatonComponent>
{
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 = Loc.GetString("Eject cell (cell missing)");
data.Visibility = VerbVisibility.Disabled;
}
else
{
data.Text = Loc.GetString("Eject cell");
}
}
protected override void Activate(IEntity user, StunbatonComponent component)
{
component.EjectCell(user);
}
}
public void DoHit(ThrowCollideEventArgs eventArgs)
{
if (!Activated || Cell == null || !Cell.TryUseCharge(EnergyPerUse) || !eventArgs.Target.TryGetComponent(out StunnableComponent stunnable))
if (!Activated || Cell == null || !Cell.TryUseCharge(EnergyPerUse) || !eventArgs.Target.TryGetComponent(out StunnableComponent? stunnable))
return;
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Weapons/egloves.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));