SETLINE.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Sets the bounds of this line object (for its touchOn, touchOff, and across scripts).
  6. /// Lines are actually 3d hitboxes, not lines.
  7. /// </summary>
  8. internal sealed class SETLINE : JsmInstruction
  9. {
  10. private readonly Coords3D _p1;
  11. private readonly Coords3D _p2;
  12. public SETLINE(Int32 x1, Int32 y1, Int32 z1, Int32 x2, Int32 y2, Int32 z2)
  13. {
  14. _p1 = new Coords3D(x1, y1, z1);
  15. _p2 = new Coords3D(x2, y2, z2);
  16. }
  17. public SETLINE(Int32 parameter, IStack<IJsmExpression> stack)
  18. : this(
  19. z2: ((IConstExpression)stack.Pop()).Int32(),
  20. y2: ((IConstExpression)stack.Pop()).Int32(),
  21. x2: ((IConstExpression)stack.Pop()).Int32(),
  22. z1: ((IConstExpression)stack.Pop()).Int32(),
  23. y1: ((IConstExpression)stack.Pop()).Int32(),
  24. x1: ((IConstExpression)stack.Pop()).Int32())
  25. {
  26. }
  27. public override String ToString()
  28. {
  29. return $"{nameof(SETLINE)}({nameof(_p1)}: {_p1}, {nameof(_p2)}: {_p2})";
  30. }
  31. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  32. {
  33. sw.Format(formatterContext, services)
  34. .Property(nameof(FieldObject.Model))
  35. .Method(nameof(FieldObjectModel.SetHitbox))
  36. .Argument("p1", _p1.ToString())
  37. .Argument("p2", _p2.ToString())
  38. .Comment(nameof(SETLINE));
  39. }
  40. public override IAwaitable TestExecute(IServices services)
  41. {
  42. FieldObject currentObject = ServiceId.Field[services].Engine.CurrentObject;
  43. currentObject.Model.SetHitbox(_p1, _p2);
  44. return DummyAwaitable.Instance;
  45. }
  46. }
  47. }