Skip to content

Commit 87d9ed9

Browse files
authored
refactor: new Npc metod to start with try when returning bool (#857)
* rename new Npc metod to start with try when returning bool TryMethod * fix: error
1 parent b6dcb68 commit 87d9ed9

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

  • EXILED/Exiled.API/Features

EXILED/Exiled.API/Features/Npc.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,10 @@ public bool TryLookAtDirection(Vector3 dir, float lerp = 1)
442442
/// </summary>
443443
/// <param name="jumpStrength">The strength used to jump. Null will choose the default one.</param>
444444
/// <returns>True if successful.</returns>
445-
public bool Jump(float? jumpStrength = null)
445+
public bool TryJump(float? jumpStrength = null)
446446
{
447447
if (Role is not FpcRole fpcRole)
448-
{
449448
return false;
450-
}
451449

452450
fpcRole.Jump(jumpStrength);
453451
return true;
@@ -458,16 +456,14 @@ public bool Jump(float? jumpStrength = null)
458456
/// </summary>
459457
/// <param name="candyKind">The kind of candy to eat.</param>
460458
/// <returns>True if successful.</returns>
461-
public bool EatCandy(CandyKindID candyKind)
459+
public bool TryEatCandy(CandyKindID candyKind)
462460
{
463461
foreach(Item? item in Items)
464462
{
465463
if (item is not Scp330 scp330)
466-
{
467464
continue;
468-
}
469465

470-
return EatCandy(scp330, candyKind);
466+
return TryEatCandy(scp330, candyKind);
471467
}
472468

473469
return false;
@@ -479,7 +475,7 @@ public bool EatCandy(CandyKindID candyKind)
479475
/// <param name="from">The <see cref="Scp330"/> bag.</param>
480476
/// <param name="candyKind">The kind of candy to eat.</param>
481477
/// <returns>True if successful.</returns>
482-
public bool EatCandy(Scp330 from, CandyKindID candyKind)
478+
public bool TryEatCandy(Scp330 from, CandyKindID candyKind)
483479
{
484480
for (int i = 0; i < from.Candies.Count; i++)
485481
{
@@ -535,24 +531,24 @@ public void CancelUseItem(Item item)
535531
/// </summary>
536532
/// <param name="hold">Specifies if the shooting is to be held.</param>
537533
/// <returns>True if successful.</returns>
538-
public bool Shoot(bool hold) =>
539-
RunItemAction(CurrentItem, ActionName.Shoot, hold);
534+
public bool TryShoot(bool hold) =>
535+
TryRunItemAction(CurrentItem, ActionName.Shoot, hold);
540536

541537
/// <summary>
542538
/// Forces the Npc to reload.
543539
/// </summary>
544540
/// <param name="hold">Specifies if the reloading is to be held.</param>
545541
/// <returns>True if successful.</returns>
546-
public bool Reload(bool hold) =>
547-
RunItemAction(CurrentItem, ActionName.Reload, hold);
542+
public bool TryReload(bool hold) =>
543+
TryRunItemAction(CurrentItem, ActionName.Reload, hold);
548544

549545
/// <summary>
550546
/// Forces the Npc to zoom.
551547
/// </summary>
552548
/// <param name="hold">Specifies if the zooming is to be held.</param>
553549
/// <returns>True if successful.</returns>
554-
public bool Zoom(bool hold) =>
555-
RunItemAction(CurrentItem, ActionName.Zoom, hold);
550+
public bool TryZoom(bool hold) =>
551+
TryRunItemAction(CurrentItem, ActionName.Zoom, hold);
556552

557553
/// <summary>
558554
/// Forces the Npc to run generic action with item.
@@ -561,17 +557,17 @@ public bool Zoom(bool hold) =>
561557
/// <param name="name">The name of action to force.</param>
562558
/// <param name="hold">Specifies if the action is to be held.</param>
563559
/// <returns>True if successful.</returns>
564-
public bool RunItemAction(Item item, ActionName name, bool hold = true) =>
565-
RunAction(item?.DummyEmulator, name, hold);
560+
public bool TryRunItemAction(Item item, ActionName name, bool hold = true) =>
561+
TryRunAction(item?.DummyEmulator, name, hold);
566562

567563
/// <summary>
568564
/// Forces the Npc to stop generic action with item.
569565
/// </summary>
570566
/// <param name="item">The <see cref="Item"/> to stop action for.</param>
571567
/// <param name="name">The name of action to stop.</param>
572568
/// <returns>True if successful.</returns>
573-
public bool StopItemAction(Item item, ActionName name) =>
574-
StopAction(item?.DummyEmulator, name);
569+
public bool TryStopItemAction(Item item, ActionName name) =>
570+
TryStopAction(item?.DummyEmulator, name);
575571

576572
/// <summary>
577573
/// Checks if certain action is currently active.
@@ -590,9 +586,9 @@ public bool IsBeingDone(Item item, ActionName name) =>
590586
/// <param name="hold">Specifies if the action is to be held.</param>
591587
/// <typeparam name="T"><see cref="SubroutineBase"/>.</typeparam>
592588
/// <returns>True if successful.</returns>
593-
public bool RunSubroutineAction<T>(T subroutine, ActionName name, bool hold = true)
589+
public bool TryRunSubroutineAction<T>(T subroutine, ActionName name, bool hold = true)
594590
where T : SubroutineBase =>
595-
RunAction(subroutine?.DummyEmulator, name, hold);
591+
TryRunAction(subroutine?.DummyEmulator, name, hold);
596592

597593
/// <summary>
598594
/// Forces the Npc to stop generic action with subroutine.
@@ -601,9 +597,9 @@ public bool RunSubroutineAction<T>(T subroutine, ActionName name, bool hold = tr
601597
/// <param name="name">The name of action to stop.</param>
602598
/// <typeparam name="T"><see cref="SubroutineBase"/>.</typeparam>
603599
/// <returns>True if successful.</returns>
604-
public bool StopSubroutineAction<T>(T subroutine, ActionName name)
600+
public bool TryStopSubroutineAction<T>(T subroutine, ActionName name)
605601
where T : SubroutineBase =>
606-
StopAction(subroutine?.DummyEmulator, name);
602+
TryStopAction(subroutine?.DummyEmulator, name);
607603

608604
/// <summary>
609605
/// Checks if certain action is currently active.
@@ -623,7 +619,7 @@ public bool IsBeingDone<T>(T subroutine, ActionName name)
623619
/// <param name="name">The name of action to force.</param>
624620
/// <param name="hold">Specifies if the action is to be held.</param>
625621
/// <returns>True if successful.</returns>
626-
public bool RunAction(DummyKeyEmulator? emulator, ActionName name, bool hold)
622+
public bool TryRunAction(DummyKeyEmulator? emulator, ActionName name, bool hold)
627623
{
628624
if (emulator == null)
629625
return false;
@@ -638,7 +634,7 @@ public bool RunAction(DummyKeyEmulator? emulator, ActionName name, bool hold)
638634
/// <param name="emulator">The <see cref="DummyKeyEmulator"/> to stop action for.</param>
639635
/// <param name="name">The name of action to stop.</param>
640636
/// <returns>True if successful.</returns>
641-
public bool StopAction(DummyKeyEmulator? emulator, ActionName name)
637+
public bool TryStopAction(DummyKeyEmulator? emulator, ActionName name)
642638
{
643639
if (emulator == null)
644640
return false;

0 commit comments

Comments
 (0)