GameInstance.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using NTERA.Core.Interop;
  2. namespace NTERA.Core
  3. {
  4. public class GameInstance
  5. {
  6. public IConsole Console { get; protected set; }
  7. public IScriptEngine ScriptEngine { get; set; }
  8. public void Run(IConsole console, IScriptEngine scriptEngine)
  9. {
  10. Console = console;
  11. ScriptEngine = scriptEngine;
  12. if (!ScriptEngine.Initialize(Console))
  13. return;
  14. ScriptEngine.Start();
  15. }
  16. public void GiveInput(string input)
  17. {
  18. InputRequest currentRequest = Console.CurrentRequest;
  19. if (Console.CurrentRequest != null)
  20. {
  21. switch (currentRequest.InputType)
  22. {
  23. case InputType.IntValue:
  24. long inputValue;
  25. if (string.IsNullOrEmpty(input) && currentRequest.HasDefValue)// && !IsRunningTimer)
  26. {
  27. inputValue = currentRequest.DefIntValue;
  28. input = inputValue.ToString();
  29. }
  30. else if (!long.TryParse(input, out inputValue))
  31. {
  32. break;
  33. }
  34. if (currentRequest.IsSystemInput)
  35. ScriptEngine.InputSystemInteger(inputValue);
  36. else
  37. ScriptEngine.InputInteger(inputValue);
  38. break;
  39. case InputType.StrValue:
  40. if (string.IsNullOrEmpty(input) && currentRequest.HasDefValue)// && !IsRunningTimer)
  41. input = currentRequest.DefStrValue;
  42. ScriptEngine.InputString(input ?? "");
  43. break;
  44. }
  45. }
  46. Console.GiveInput(input);
  47. }
  48. }
  49. }