AMES.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Pop up a message window until WINCLOSE or MESSYNC is called.
  6. /// </summary>
  7. internal sealed class AMES : JsmInstruction
  8. {
  9. private readonly Int32 _channel;
  10. private readonly Int32 _messageId;
  11. private readonly Int32 _posX;
  12. private readonly Int32 _posY;
  13. public AMES(Int32 channel, Int32 messageId, Int32 posX, Int32 posY)
  14. {
  15. _channel = channel;
  16. _messageId = messageId;
  17. _posX = posX;
  18. _posY = posY;
  19. }
  20. public AMES(Int32 parameter, IStack<IJsmExpression> stack)
  21. : this(
  22. posY: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  23. posX: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  24. messageId: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  25. channel: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32())
  26. {
  27. }
  28. public override String ToString()
  29. {
  30. return $"{nameof(AMES)}({nameof(_channel)}: {_channel}, {nameof(_messageId)}: {_messageId}, {nameof(_posX)}: {_posX}, {nameof(_posY)}: {_posY})";
  31. }
  32. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  33. {
  34. FormatHelper.FormatMonologue(sw, formatterContext.GetMessage(_messageId));
  35. sw.Format(formatterContext, services)
  36. .StaticType(nameof(IMessageService))
  37. .Method(nameof(IMessageService.Show))
  38. .Argument("channel", _channel)
  39. .Argument("messageId", _messageId)
  40. .Argument("posX", _posX)
  41. .Argument("posY", _posY)
  42. .Comment(nameof(AMES));
  43. }
  44. public override IAwaitable TestExecute(IServices services)
  45. {
  46. ServiceId.Message[services].Show(_channel, _messageId, _posX, _posY);
  47. return DummyAwaitable.Instance;
  48. }
  49. }
  50. }