-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
191 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ public enum AlertType : byte | |
BorgHealth, | ||
BorgCrit, | ||
BorgDead, | ||
Offering | ||
Offer | ||
} | ||
|
||
} |
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
6 changes: 3 additions & 3 deletions
6
...red/OfferingItem/OfferingItemComponent.cs → ...nt.Shared/OfferItem/OfferItemComponent.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
73 changes: 73 additions & 0 deletions
73
Content.Shared/OfferItem/SharedOfferItemSystem.Interactions.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,73 @@ | ||
using Content.Shared.ActionBlocker; | ||
using Content.Shared.Input; | ||
using Content.Shared.Hands.Components; | ||
using Robust.Shared.Input.Binding; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Shared.OfferItem; | ||
|
||
public abstract partial class SharedOfferItemSystem | ||
{ | ||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; | ||
|
||
private void InitializeInteractions() | ||
{ | ||
CommandBinds.Builder | ||
.Bind(ContentKeyFunctions.OfferItem, InputCmdHandler.FromDelegate(SetInOfferMode, handle: false, outsidePrediction: false)) | ||
.Register<SharedOfferItemSystem>(); | ||
} | ||
|
||
public override void Shutdown() | ||
{ | ||
base.Shutdown(); | ||
|
||
CommandBinds.Unregister<SharedOfferItemSystem>(); | ||
} | ||
|
||
private void SetInOfferMode(ICommonSession? session) | ||
{ | ||
if (session is not { } playerSession) | ||
return; | ||
|
||
if ((playerSession.AttachedEntity is not { Valid: true } uid || !Exists(uid)) || | ||
!_actionBlocker.CanInteract(uid, null)) | ||
return; | ||
|
||
if (!TryComp<OfferItemComponent>(uid, out var offerItem)) | ||
return; | ||
|
||
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null) | ||
return; | ||
|
||
var handItem = hands.ActiveHand.HeldEntity; | ||
|
||
if (offerItem.IsInOfferMode == false) | ||
{ | ||
if (handItem == null) | ||
return; | ||
|
||
if (offerItem.Hand == null || offerItem.Target == null) | ||
{ | ||
offerItem.IsInOfferMode = true; | ||
offerItem.Hand = hands.ActiveHand.Name; | ||
|
||
Dirty(uid, offerItem); | ||
return; | ||
} | ||
|
||
if (TryComp<OfferItemComponent>(offerItem.Target, out var offerItemTarget)) | ||
{ | ||
offerItemTarget.IsInReceiveMode = false; | ||
offerItemTarget.Target = null; | ||
|
||
Dirty(offerItem.Target.Value, offerItemTarget); | ||
} | ||
} | ||
|
||
offerItem.Hand = null; | ||
offerItem.IsInOfferMode = false; | ||
offerItem.Target = null; | ||
|
||
Dirty(uid, offerItem); | ||
} | ||
} |
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,67 @@ | ||
using Content.Shared.Interaction; | ||
|
||
namespace Content.Shared.OfferItem; | ||
|
||
public abstract partial class SharedOfferItemSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<OfferItemComponent, AfterInteractUsingEvent>(SetInReceiveMode); | ||
SubscribeLocalEvent<OfferItemComponent, MoveEvent>(OnMove); | ||
|
||
InitializeInteractions(); | ||
} | ||
|
||
private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, AfterInteractUsingEvent args) | ||
{ | ||
if (!TryComp<OfferItemComponent>(args.User, out var offerItem)) | ||
return; | ||
|
||
component.IsInReceiveMode = true; | ||
component.Target = args.User; | ||
|
||
Dirty(uid, component); | ||
|
||
offerItem.Target = uid; | ||
offerItem.IsInOfferMode = false; | ||
|
||
Dirty(args.User, offerItem); | ||
} | ||
|
||
private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args) | ||
{ | ||
if (component.Target == null || | ||
args.NewPosition.InRange(EntityManager, _transform, | ||
Transform(component.Target.GetValueOrDefault()).Coordinates, component.MaxOfferDistance)) | ||
return; | ||
|
||
UnOffer(uid, component); | ||
} | ||
|
||
protected void UnOffer(EntityUid uid, OfferItemComponent component) | ||
{ | ||
if (TryComp<OfferItemComponent>(component.Target, out var offerItem) && component.Target != null) | ||
{ | ||
offerItem.IsInOfferMode = false; | ||
offerItem.IsInReceiveMode = false; | ||
offerItem.Hand = null; | ||
offerItem.Target = null; | ||
|
||
Dirty(component.Target.Value, offerItem); | ||
} | ||
|
||
component.IsInOfferMode = false; | ||
component.IsInReceiveMode = false; | ||
component.Hand = null; | ||
component.Target = null; | ||
|
||
Dirty(uid, component); | ||
} | ||
|
||
public bool IsInOfferMode(EntityUid? entity, OfferItemComponent? component = null) | ||
{ | ||
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode; | ||
} | ||
} |
Oops, something went wrong.