2
0

PREQSW.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Requests that the entity associated with a character in the current party executes one of its member functions at a specified priority.
  6. /// If the specified priority is already busy executing, the request will block until it becomes available and only then return.
  7. /// The remote execution is still carried out asynchronously, with no notification of completion.
  8. /// </summary>
  9. internal sealed class PREQSW : JsmInstruction
  10. {
  11. private Int32 _partyId;
  12. private Int32 _priority;
  13. private Int32 _scriptId;
  14. public PREQSW(Int32 partyId, Int32 priority, Int32 scriptId)
  15. {
  16. _partyId = partyId;
  17. _priority = priority;
  18. _scriptId = scriptId;
  19. }
  20. public PREQSW(Int32 partyId, IStack<IJsmExpression> stack)
  21. : this(partyId,
  22. scriptId: ((IConstExpression)stack.Pop()).Int32(),
  23. priority: ((IConstExpression)stack.Pop()).Int32())
  24. {
  25. }
  26. public override String ToString()
  27. {
  28. return $"{nameof(PREQSW)}({nameof(_partyId)}: {_partyId}, {nameof(_priority)}: {_priority}, {nameof(_scriptId)}: {_scriptId})";
  29. }
  30. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  31. {
  32. formatterContext.GetObjectScriptNamesById(_scriptId, out String typeName, out String methodName);
  33. sw.AppendLine($"{nameof(PREQSW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
  34. }
  35. public override IAwaitable TestExecute(IServices services)
  36. {
  37. FieldObject targetObject = ServiceId.Party[services].FindPartyCharacterObject(_partyId);
  38. if (targetObject == null)
  39. throw new NotSupportedException($"Unknown expected behavior when trying to call a method of a nonexistent party character (Slot: {_partyId}).");
  40. if (!targetObject.IsActive)
  41. throw new NotSupportedException($"Unknown expected behavior when trying to call a method of the inactive object (Slot: {_partyId}).");
  42. targetObject.Scripts.Execute(_scriptId, _priority);
  43. return DummyAwaitable.Instance;
  44. }
  45. }
  46. }