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

@@ -11,14 +11,28 @@ namespace Content.Server.GameObjects.Components.Power
{
public override string Name => "Battery";
/// <summary>
/// Maximum charge of the battery in joules (ie. watt seconds)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public int MaxCharge { get => _maxCharge; set => SetMaxCharge(value); }
private int _maxCharge;
/// <summary>
/// Current charge of the battery in joules (ie. watt seconds)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float CurrentCharge { get => _currentCharge; set => SetCurrentCharge(value); }
private float _currentCharge;
/// <summary>
/// True if the battery is fully charged.
/// </summary>
[ViewVariables] public bool IsFullyCharged => MathHelper.CloseTo(CurrentCharge, MaxCharge);
[ViewVariables(VVAccess.ReadWrite)] public bool AutoRecharge { get; set; }
[ViewVariables(VVAccess.ReadWrite)] public float AutoRechargeRate { get; set; }
[ViewVariables] public BatteryState BatteryState { get; private set; }
public override void ExposeData(ObjectSerializer serializer)
@@ -26,6 +40,8 @@ namespace Content.Server.GameObjects.Components.Power
base.ExposeData(serializer);
serializer.DataField(ref _maxCharge, "maxCharge", 1000);
serializer.DataField(ref _currentCharge, "startingCharge", 500);
serializer.DataField(this, x => x.AutoRecharge, "autoRecharge", false);
serializer.DataField(this, x => x.AutoRechargeRate, "autoRechargeRate", 0);
}
public override void Initialize()
@@ -75,7 +91,7 @@ namespace Content.Server.GameObjects.Components.Power
private void UpdateStorageState()
{
if (CurrentCharge == MaxCharge)
if (IsFullyCharged)
{
BatteryState = BatteryState.Full;
}
@@ -103,6 +119,13 @@ namespace Content.Server.GameObjects.Components.Power
UpdateStorageState();
OnChargeChanged();
}
public void OnUpdate(float frameTime)
{
if (!AutoRecharge) return;
if (IsFullyCharged) return;
CurrentCharge += AutoRechargeRate * frameTime;
}
}
public enum BatteryState