VariableStrArgTerm.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using NTERA.EmuEra.Game.EraEmu.GameData.Expression;
  4. using NTERA.EmuEra.Game.EraEmu.Sub;
  5. namespace NTERA.EmuEra.Game.EraEmu.GameData.Variable
  6. {
  7. //変数の引数のうち文字列型のもの。
  8. internal sealed class VariableStrArgTerm : IOperandTerm
  9. {
  10. public VariableStrArgTerm(VariableCode code, IOperandTerm strTerm, int index)
  11. : base(typeof(Int64))
  12. {
  13. this.strTerm = strTerm;
  14. parentCode = code;
  15. this.index = index;
  16. }
  17. IOperandTerm strTerm;
  18. readonly VariableCode parentCode;
  19. readonly int index;
  20. Dictionary<string, int> dic;
  21. string errPos;
  22. public override Int64 GetIntValue(ExpressionMediator exm)
  23. {
  24. if (dic == null)
  25. dic = exm.VEvaluator.Constant.GetKeywordDictionary(out errPos, parentCode, index);
  26. string key = strTerm.GetStrValue(exm);
  27. if (key == "")
  28. throw new CodeEE("キーワードを空には出来ません");
  29. int i;
  30. if (!dic.TryGetValue(key, out i))
  31. {
  32. if (errPos == null)
  33. throw new CodeEE("配列変数" + parentCode + "の要素を文字列で指定することはできません");
  34. throw new CodeEE(errPos + "の中に\"" + key + "\"の定義がありません");
  35. }
  36. return i;
  37. }
  38. public override IOperandTerm Restructure(ExpressionMediator exm, bool tryTranslate=false)
  39. {
  40. if (dic == null)
  41. dic = exm.VEvaluator.Constant.GetKeywordDictionary(out errPos, parentCode, index);
  42. strTerm = strTerm.Restructure(exm);
  43. if (!(strTerm is SingleTerm))
  44. return this;
  45. return new SingleTerm(GetIntValue(exm));
  46. }
  47. }
  48. }