HALT.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Exits the current script and all scripts that are waiting on it. To end only the current script, use RET instead.
  6. /// </summary>
  7. internal sealed class HALT : JsmInstruction
  8. {
  9. private Int32 _parameter;
  10. public HALT(Int32 parameter)
  11. {
  12. _parameter = parameter;
  13. }
  14. public HALT(Int32 parameter, IStack<IJsmExpression> stack)
  15. : this(parameter)
  16. {
  17. }
  18. public override String ToString()
  19. {
  20. return $"{nameof(HALT)}({nameof(_parameter)}: {_parameter})";
  21. }
  22. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  23. {
  24. sw.Format(formatterContext, services)
  25. .Property(nameof(FieldObject.Scripts))
  26. .Method(nameof(FieldObjectScripts.CancelAll))
  27. .Comment(nameof(HALT));
  28. }
  29. public override IAwaitable TestExecute(IServices services)
  30. {
  31. FieldObject currentObject = ServiceId.Field[services].Engine.CurrentObject;
  32. currentObject.Scripts.CancelAll();
  33. return BreakAwaitable.Instance;
  34. }
  35. }
  36. }