-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2800 from Spielern/port-ipc
Ports IPCs from Goob/EE
- Loading branch information
Showing
183 changed files
with
7,558 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Content.Server/_EE/Power/Components/BatteryDrinkerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Content.Server._EE.Power.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class BatteryDrinkerComponent : Component | ||
{ | ||
/// <summary> | ||
/// Is this drinker allowed to drink batteries not tagged as <see cref="BatteryDrinkSource"/>? | ||
/// </summary> | ||
[DataField] | ||
public bool DrinkAll; | ||
|
||
/// <summary> | ||
/// How long it takes to drink from a battery, in seconds. | ||
/// Is multiplied by the source. | ||
/// </summary> | ||
[DataField] | ||
public float DrinkSpeed = 1.5f; | ||
|
||
/// <summary> | ||
/// The multiplier for the amount of power to attempt to drink. | ||
/// Default amount is 1000 | ||
/// </summary> | ||
[DataField] | ||
public float DrinkMultiplier = 5f; | ||
|
||
/// <summary> | ||
/// The multiplier for how long it takes to drink a non-source battery, if <see cref="DrinkAll"/> is true. | ||
/// </summary> | ||
[DataField] | ||
public float DrinkAllMultiplier = 2.5f; | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Server/_EE/Power/Components/RandomBatteryChargeComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Numerics; | ||
|
||
namespace Content.Server._EE.Power.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class RandomBatteryChargeComponent : Component | ||
{ | ||
/// <summary> | ||
/// The minimum and maximum max charge the battery can have. | ||
/// </summary> | ||
[DataField] | ||
public Vector2 BatteryMaxMinMax = new(0.85f, 1.15f); | ||
|
||
/// <summary> | ||
/// The minimum and maximum current charge the battery can have. | ||
/// </summary> | ||
[DataField] | ||
public Vector2 BatteryChargeMinMax = new(1f, 1f); | ||
|
||
/// <summary> | ||
/// False if the randomized charge of the battery should be a multiple of the preexisting current charge of the battery. | ||
/// True if the randomized charge of the battery should be a multiple of the max charge of the battery post max charge randomization. | ||
/// </summary> | ||
[DataField] | ||
public bool BasedOnMaxCharge = true; | ||
} |
143 changes: 143 additions & 0 deletions
143
Content.Server/_EE/Power/Systems/BatteryDrinkerSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
using System.Linq; | ||
using Content.Server.Power.Components; | ||
using Content.Shared.Containers.ItemSlots; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.PowerCell.Components; | ||
using Content.Shared._EE.Silicon; | ||
using Content.Shared.Verbs; | ||
using Robust.Shared.Utility; | ||
using Content.Server._EE.Silicon.Charge; | ||
using Content.Server.Power.EntitySystems; | ||
using Content.Server.Popups; | ||
using Content.Server.PowerCell; | ||
using Content.Shared.Popups; | ||
using Robust.Shared.Audio.Systems; | ||
using Robust.Shared.Containers; | ||
using Content.Server._EE.Power.Components; | ||
using Content.Server._EE.Silicon; | ||
|
||
namespace Content.Server._EE.Power; | ||
|
||
public sealed class BatteryDrinkerSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ItemSlotsSystem _slots = default!; | ||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!; | ||
[Dependency] private readonly SharedAudioSystem _audio = default!; | ||
[Dependency] private readonly BatterySystem _battery = default!; | ||
[Dependency] private readonly SiliconChargeSystem _silicon = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
[Dependency] private readonly PowerCellSystem _powerCell = default!; | ||
[Dependency] private readonly SharedContainerSystem _container = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<BatteryComponent, GetVerbsEvent<AlternativeVerb>>(AddAltVerb); | ||
|
||
SubscribeLocalEvent<BatteryDrinkerComponent, BatteryDrinkerDoAfterEvent>(OnDoAfter); | ||
} | ||
|
||
private void AddAltVerb(EntityUid uid, BatteryComponent batteryComponent, GetVerbsEvent<AlternativeVerb> args) | ||
{ | ||
if (!args.CanAccess || !args.CanInteract) | ||
return; | ||
|
||
if (!TryComp<BatteryDrinkerComponent>(args.User, out var drinkerComp) || | ||
!TestDrinkableBattery(uid, drinkerComp) || | ||
!_silicon.TryGetSiliconBattery(args.User, out var drinkerBattery)) | ||
return; | ||
|
||
AlternativeVerb verb = new() | ||
{ | ||
Act = () => DrinkBattery(uid, args.User, drinkerComp), | ||
Text = Loc.GetString("battery-drinker-verb-drink"), | ||
Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/smite.svg.192dpi.png")), | ||
}; | ||
|
||
args.Verbs.Add(verb); | ||
} | ||
|
||
private bool TestDrinkableBattery(EntityUid target, BatteryDrinkerComponent drinkerComp) | ||
{ | ||
if (!drinkerComp.DrinkAll && !HasComp<BatteryDrinkerSourceComponent>(target)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerComponent drinkerComp) | ||
{ | ||
var doAfterTime = drinkerComp.DrinkSpeed; | ||
|
||
if (TryComp<BatteryDrinkerSourceComponent>(target, out var sourceComp)) | ||
doAfterTime *= sourceComp.DrinkSpeedMulti; | ||
else | ||
doAfterTime *= drinkerComp.DrinkAllMultiplier; | ||
|
||
var args = new DoAfterArgs(EntityManager, user, doAfterTime, new BatteryDrinkerDoAfterEvent(), user, target) // TODO: Make this doafter loop, once we merge Upstream. | ||
{ | ||
BreakOnDamage = true, | ||
BreakOnMove = true, | ||
Broadcast = false, | ||
DistanceThreshold = 1.35f, | ||
RequireCanInteract = true, | ||
CancelDuplicate = false | ||
}; | ||
|
||
_doAfter.TryStartDoAfter(args); | ||
} | ||
|
||
private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAfterEvent args) | ||
{ | ||
if (args.Cancelled || args.Target == null) | ||
return; | ||
|
||
var source = args.Target.Value; | ||
var drinker = uid; | ||
var sourceBattery = Comp<BatteryComponent>(source); | ||
|
||
_silicon.TryGetSiliconBattery(drinker, out var drinkerBatteryComponent); | ||
|
||
if (!TryComp(uid, out PowerCellSlotComponent? batterySlot)) | ||
return; | ||
|
||
var container = _container.GetContainer(uid, batterySlot.CellSlotId); | ||
var drinkerBattery = container.ContainedEntities.First(); | ||
|
||
TryComp<BatteryDrinkerSourceComponent>(source, out var sourceComp); | ||
|
||
DebugTools.AssertNotNull(drinkerBattery); | ||
|
||
if (drinkerBattery == null) | ||
return; | ||
|
||
var amountToDrink = drinkerComp.DrinkMultiplier * 1000; | ||
|
||
amountToDrink = MathF.Min(amountToDrink, sourceBattery.CurrentCharge); | ||
amountToDrink = MathF.Min(amountToDrink, drinkerBatteryComponent!.MaxCharge - drinkerBatteryComponent.CurrentCharge); | ||
|
||
if (sourceComp != null && sourceComp.MaxAmount > 0) | ||
amountToDrink = MathF.Min(amountToDrink, (float) sourceComp.MaxAmount); | ||
|
||
if (amountToDrink <= 0) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), drinker, drinker); | ||
return; | ||
} | ||
|
||
if (_battery.TryUseCharge(source, amountToDrink)) | ||
_battery.SetCharge(drinkerBattery, drinkerBatteryComponent.CurrentCharge + amountToDrink, drinkerBatteryComponent); | ||
else | ||
{ | ||
_battery.SetCharge(drinkerBattery, sourceBattery.CurrentCharge + drinkerBatteryComponent.CurrentCharge, drinkerBatteryComponent); | ||
_battery.SetCharge(source, 0); | ||
} | ||
|
||
if (sourceComp != null && sourceComp.DrinkSound != null){ | ||
_popup.PopupEntity(Loc.GetString("ipc-recharge-tip"), drinker, drinker, PopupType.SmallCaution); | ||
_audio.PlayPvs(sourceComp.DrinkSound, source); | ||
Spawn("EffectSparks", Transform(source).Coordinates); | ||
} | ||
} | ||
} |
Oops, something went wrong.