| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- namespace OpenVIII.Fields.Scripts.Instructions
- {
- /// <summary>
- /// Requests that the entity associated with a character in the current party executes one of its member functions at a specified priority.
- /// If the specified priority is already busy executing, the request will block until it becomes available and only then return.
- /// The remote execution is still carried out asynchronously, with no notification of completion.
- /// </summary>
- /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/Field/Script/Opcodes/018_PREQSW"/>
- public sealed class PREQSW : Abstract.PREQ
- {
- #region Constructors
- public PREQSW(int objectIndex, IStack<IJsmExpression> stack) : base(objectIndex, stack)
- {
- }
- public PREQSW(int objectIndex, int priority, int scriptId) : base(objectIndex, priority, scriptId)
- {
- }
- #endregion Constructors
- #region Methods
- public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
- {
- formatterContext.GetObjectScriptNamesById(_scriptId, out var typeName, out var methodName);
- sw.AppendLine($"{nameof(PREQSW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
- }
- public override IAwaitable TestExecute(IServices services)
- {
- var targetObject = ServiceId.Party[services].FindPartyCharacterObject(_partyId);
- if (targetObject == null)
- throw new NotSupportedException($"Unknown expected behavior when trying to call a method of a nonexistent party character (Slot: {_partyId}).");
- if (!targetObject.IsActive)
- throw new NotSupportedException($"Unknown expected behavior when trying to call a method of the inactive object (Slot: {_partyId}).");
- targetObject.Scripts.Execute(_scriptId, _priority);
- return DummyAwaitable.Instance;
- }
- public override string ToString() => $"{nameof(PREQSW)}({nameof(_partyId)}: {_partyId}, {nameof(_priority)}: {_priority}, {nameof(_scriptId)}: {_scriptId})";
- #endregion Methods
- }
- }
|