SET.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Place this entity's model at XCoord, YCoord standing on the given walkmesh triangle. Unlike SET3, this function will place the event on the walkable terrain (the ZCoord is interpolated from the walkmesh).
  6. /// </summary>
  7. internal sealed class SET : JsmInstruction
  8. {
  9. private Int32 _walkmeshTriangleId;
  10. private Int32 _x;
  11. private Int32 _y;
  12. public SET(Int32 walkmeshTriangleId, Int32 x, Int32 y)
  13. {
  14. _walkmeshTriangleId = walkmeshTriangleId;
  15. _x = x;
  16. _y = y;
  17. }
  18. public SET(Int32 walkmeshTriangleId, IStack<IJsmExpression> stack)
  19. : this(walkmeshTriangleId,
  20. y: ((IConstExpression)stack.Pop()).Int32(),
  21. x: ((IConstExpression)stack.Pop()).Int32())
  22. {
  23. }
  24. public override String ToString()
  25. {
  26. return $"{nameof(SET)}({nameof(_walkmeshTriangleId)}: {_walkmeshTriangleId}, {nameof(_x)}: {_x}, {nameof(_y)}: {_y})";
  27. }
  28. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  29. {
  30. sw.Format(formatterContext, services)
  31. .Property(nameof(FieldObject.Model))
  32. .Method(nameof(FieldObjectModel.SetPosition))
  33. .Argument("walkmeshTriangleId", _walkmeshTriangleId)
  34. .Argument("x", _x)
  35. .Argument("y", _y)
  36. .Comment(nameof(SET3));
  37. }
  38. public override IAwaitable TestExecute(IServices services)
  39. {
  40. FieldObject currentObject = ServiceId.Field[services].Engine.CurrentObject;
  41. currentObject.Model.SetPosition(new WalkmeshCoords(_walkmeshTriangleId, _x, _y));
  42. return DummyAwaitable.Instance;
  43. }
  44. }
  45. }