CTURN.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. namespace OpenVIII.Fields.Scripts.Instructions
  2. {
  3. /// <summary>
  4. /// Make this entity face the entity with the ID of the first parameter.
  5. /// </summary>
  6. internal sealed class CTURN : JsmInstruction
  7. {
  8. #region Fields
  9. private readonly IJsmExpression _frameDuration;
  10. private readonly int _targetObject;
  11. #endregion Fields
  12. #region Constructors
  13. public CTURN(int targetObject, IJsmExpression frameDuration)
  14. {
  15. _targetObject = targetObject;
  16. _frameDuration = frameDuration;
  17. }
  18. public CTURN(int parameter, IStack<IJsmExpression> stack)
  19. : this(
  20. frameDuration: stack.Pop(),
  21. targetObject: ((IConstExpression)stack.Pop()).Int32())
  22. {
  23. }
  24. #endregion Constructors
  25. #region Methods
  26. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.Format(formatterContext, services)
  27. .Await()
  28. .Property(nameof(FieldObject.Model))
  29. .Method(nameof(FieldObjectModel.RotateToObject))
  30. .Argument("targetObject", _targetObject)
  31. .Argument("frameDuration", _frameDuration)
  32. .Comment(nameof(CTURN));
  33. public override IAwaitable TestExecute(IServices services)
  34. {
  35. var currentObject = ServiceId.Field[services].Engine.CurrentObject;
  36. var frameDuration = _frameDuration.Int32(services);
  37. currentObject.Model.RotateToObject(_targetObject, frameDuration);
  38. return DummyAwaitable.Instance;
  39. }
  40. public override string ToString() => $"{nameof(CTURN)}({nameof(_targetObject)}: {_targetObject}, {nameof(_frameDuration)}: {_frameDuration})";
  41. #endregion Methods
  42. }
  43. }