Made a fancier lasergun (#174)
Laserguns now have an internal capacitor that can be recharged by using it with a power cell Makes the final fix for #138
This commit is contained in:
committed by
Pieter-Jan Briers
parent
b94e015314
commit
1af1ee2ad4
@@ -60,6 +60,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
[ViewVariables]
|
||||
public bool Full => Charge >= Capacity;
|
||||
|
||||
public event Action OnChargeChanged;
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -70,6 +71,14 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
serializer.DataField(ref _distributionRate, "distributionrate", 1000);
|
||||
}
|
||||
|
||||
protected virtual void ChargeChanged()
|
||||
{
|
||||
if (OnChargeChanged != null)
|
||||
{ //Only fire this event if anyone actually subscribes to it
|
||||
OnChargeChanged.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the storage can supply the amount of charge directly requested
|
||||
/// </summary>
|
||||
@@ -88,6 +97,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
_charge = Math.Max(0, Charge - toDeduct);
|
||||
LastChargeState = ChargeState.Discharging;
|
||||
LastChargeStateChange = DateTime.Now;
|
||||
ChargeChanged();
|
||||
}
|
||||
|
||||
public virtual void AddCharge(float charge)
|
||||
@@ -95,6 +105,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
_charge = Math.Min(Capacity, Charge + charge);
|
||||
LastChargeState = ChargeState.Charging;
|
||||
LastChargeStateChange = DateTime.Now;
|
||||
ChargeChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user