Skip to content

Commit

Permalink
another attempt?
Browse files Browse the repository at this point in the history
  • Loading branch information
gluesniffler committed Oct 28, 2024
1 parent 285c468 commit 87a2520
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
13 changes: 9 additions & 4 deletions Content.Client/Medical/Surgery/SurgeryBui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public SurgeryBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)

protected override void Open()
{
Logger.Debug("Attempting to open");
_system.OnRefresh += () =>
{
UpdateDisabledPanel();
Expand Down Expand Up @@ -68,11 +69,11 @@ protected override void Dispose(bool disposing)

private void Update(SurgeryBuiState state)
{
Logger.Debug($"Attempting to update surgerybuistate with {state}, {_player.LocalEntity}, first predicted? {_timing.IsFirstTimePredicted}, surgeryTargetComp? {_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity, out var surgeryTargetComp2)} {surgeryTargetComp2?.CanOperate}");
if (!_entities.TryGetComponent<SurgeryTargetComponent>(_player.LocalEntity, out var surgeryTargetComp)
|| !surgeryTargetComp.CanOperate
|| !_timing.IsFirstTimePredicted)
|| !surgeryTargetComp.CanOperate)
return;

Logger.Debug("Passed check");
if (_window == null)
{
_window = new SurgeryWindow();
Expand Down Expand Up @@ -195,9 +196,13 @@ int GetScore(BodyPartType? partType)


if (!_window.IsOpen)
{
Logger.Debug("Attempting to open");
_window.OpenCentered();
}
else
{
Logger.Debug("Attempting to refresh");
RefreshUI();
UpdateDisabledPanel();
}
Expand Down Expand Up @@ -452,4 +457,4 @@ private enum StepStatus
Complete,
Incomplete
}
}
}
15 changes: 7 additions & 8 deletions Content.Server/Medical/Surgery/SurgerySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ protected override void RefreshUI(EntityUid body)
}

}

_ui.TrySetUiState(body, SurgeryUIKey.Key, new SurgeryBuiState(surgeries));
Logger.Debug($"Setting UI state with {surgeries}, {body} and {SurgeryUIKey.Key}");
_ui.SetUiState(body, SurgeryUIKey.Key, new SurgeryBuiState(surgeries));
}

private void SetDamage(EntityUid body, DamageSpecifier damage, float partMultiplier,
Expand All @@ -105,8 +105,7 @@ private void OnToolAfterInteract(Entity<SurgeryToolComponent> ent, ref AfterInte
|| !args.CanReach
|| args.Target == null
|| !TryComp<SurgeryTargetComponent>(args.User, out var surgery)
|| !surgery.CanOperate
|| !TryComp(args.User, out ActorComponent? actor))
|| !surgery.CanOperate)
{
return;
}
Expand All @@ -116,10 +115,10 @@ private void OnToolAfterInteract(Entity<SurgeryToolComponent> ent, ref AfterInte
_popup.PopupEntity("You can't perform surgery on yourself!", user, user);
return;
}*/

Logger.Debug("OnToolAfterInteract passed, opening UI");
args.Handled = true;
_ui.TryOpen(args.Target.Value, SurgeryUIKey.Key, actor.PlayerSession);

_ui.OpenUi(args.Target.Value, SurgeryUIKey.Key, user);
Logger.Debug("UI opened");
RefreshUI(args.Target.Value);
}

Expand Down Expand Up @@ -212,4 +211,4 @@ private void LoadPrototypes()
_surgeries.Add(new EntProtoId(entity.ID));
}
}
}
}
14 changes: 9 additions & 5 deletions Content.Shared/Medical/Surgery/SharedSurgerySystem.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,13 @@ private void CheckAndStartStep(EntityUid user, EntityUid body, EntityUid part, E

private void OnSurgeryTargetStepChosen(Entity<SurgeryTargetComponent> ent, ref SurgeryStepChosenBuiMsg args)
{
if (args.Session.AttachedEntity is not { } user ||
GetEntity(args.Entity) is not { Valid: true } body ||
!IsSurgeryValid(body, GetEntity(args.Part), args.Surgery, args.Step, out var surgery, out var part, out var step))
var user = args.Actor;
if (GetEntity(args.Entity) is not { Valid: true } body ||
GetEntity(args.Part) is not { Valid: true } targetPart ||
!IsSurgeryValid(body, targetPart, args.Surgery, args.Step, out var surgery, out var part, out var step))
{
return;
}

if (!PreviousStepsComplete(body, part, surgery, args.Step) ||
IsStepComplete(body, part, args.Step, surgery))
Expand All @@ -482,7 +485,8 @@ private void OnSurgeryTargetStepChosen(Entity<SurgeryTargetComponent> ent, ref S
var ev = new SurgeryDoAfterEvent(args.Surgery, args.Step);
// TODO: Make this serialized on a per surgery step basis, and also add penalties based on ghetto tools.
var duration = 2f;
if (TryComp(user, out SurgerySpeedModifierComponent? surgerySpeedMod))
if (TryComp(user, out SurgerySpeedModifierComponent? surgerySpeedMod)
&& surgerySpeedMod is not null)
duration = duration / surgerySpeedMod.SpeedModifier;

var doAfter = new DoAfterArgs(EntityManager, user, TimeSpan.FromSeconds(duration), ev, body, part)
Expand Down Expand Up @@ -621,4 +625,4 @@ private bool AnyHaveComp(List<EntityUid> tools, IComponent component, out Entity
withComp = default;
return false;
}
}
}
4 changes: 2 additions & 2 deletions Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1238,8 +1238,8 @@
interfaces:
enum.StrippingUiKey.Key:
type: StrippableBoundUserInterface
enum.SurgeryUiKey.Key:
type: SurgeryBui
#enum.SurgeryUIKey.Key:
# type: SurgeryBui
- type: Sprite
drawdepth: Mobs
layers:
Expand Down

0 comments on commit 87a2520

Please sign in to comment.