FunctionMethodTerm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using NTERA.EmuEra.Game.EraEmu.GameData.Expression;
  2. namespace NTERA.EmuEra.Game.EraEmu.GameData.Function
  3. {
  4. internal sealed class FunctionMethodTerm : IOperandTerm
  5. {
  6. public FunctionMethodTerm(FunctionMethod meth, IOperandTerm[] args)
  7. : base(meth.ReturnType)
  8. {
  9. method = meth;
  10. arguments = args;
  11. }
  12. private FunctionMethod method;
  13. private IOperandTerm[] arguments;
  14. public override long GetIntValue(ExpressionMediator exm)
  15. {
  16. return method.GetIntValue(exm, arguments);
  17. }
  18. public override string GetStrValue(ExpressionMediator exm, bool translate=false)
  19. {
  20. return method.GetStrValue(exm, arguments, translate);
  21. }
  22. public override SingleTerm GetValue(ExpressionMediator exm, bool tryTranslate =false)
  23. {
  24. return method.GetReturnValue(exm, arguments, tryTranslate);
  25. }
  26. public override IOperandTerm Restructure(ExpressionMediator exm, bool tryTranslate=false)
  27. {
  28. if (method.HasUniqueRestructure)
  29. {
  30. if (method.UniqueRestructure(exm, arguments) && method.CanRestructure)
  31. return GetValue(exm);
  32. return this;
  33. }
  34. bool argIsConst = true;
  35. for(int i = 0; i< arguments.Length;i++)
  36. {
  37. if(arguments[i] == null)
  38. continue;
  39. //Changes by Bartoum
  40. //This is a place to rework. This is where constant are translated
  41. arguments[i] = arguments[i].Restructure(exm, true);
  42. argIsConst &= arguments[i] is SingleTerm;
  43. }
  44. if ((method.CanRestructure) && (argIsConst))
  45. return GetValue(exm);
  46. return this;
  47. }
  48. }
  49. }