PREQSW.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/Field/Script/Opcodes/018_PREQSW"/>
  10. public sealed class PREQSW : Abstract.PREQ
  11. {
  12. #region Constructors
  13. public PREQSW(int objectIndex, IStack<IJsmExpression> stack) : base(objectIndex, stack)
  14. {
  15. }
  16. public PREQSW(int objectIndex, int priority, int scriptId) : base(objectIndex, priority, scriptId)
  17. {
  18. }
  19. #endregion Constructors
  20. #region Methods
  21. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  22. {
  23. formatterContext.GetObjectScriptNamesById(_scriptId, out var typeName, out var methodName);
  24. sw.AppendLine($"{nameof(PREQSW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
  25. }
  26. public override IAwaitable TestExecute(IServices services)
  27. {
  28. var targetObject = ServiceId.Party[services].FindPartyCharacterObject(_partyId);
  29. if (targetObject == null)
  30. throw new NotSupportedException($"Unknown expected behavior when trying to call a method of a nonexistent party character (Slot: {_partyId}).");
  31. if (!targetObject.IsActive)
  32. throw new NotSupportedException($"Unknown expected behavior when trying to call a method of the inactive object (Slot: {_partyId}).");
  33. targetObject.Scripts.Execute(_scriptId, _priority);
  34. return DummyAwaitable.Instance;
  35. }
  36. public override string ToString() => $"{nameof(PREQSW)}({nameof(_partyId)}: {_partyId}, {nameof(_priority)}: {_priority}, {nameof(_scriptId)}: {_scriptId})";
  37. #endregion Methods
  38. }
  39. }