CTURN.cs 1.7 KB

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