public static string FormatText(string line, ScriptWrapper script) { return(Regex.Replace(line, "\\{\\{(?<VarName>.*?)\\}\\}", a => { var mvm = MainViewModel.GetMainViewModelStatic(); var varName = a.Groups["VarName"].Value; string res = "INVALID VARIABLE NAME"; VariableWrapper v = null; if (script != null) { v = script.GetVarByName(varName); } else if (mvm.CurrentGame.VarByName.ContainsKey(varName)) { v = mvm.CurrentGame.VarByName[varName]; } if (v != null) { if (v.VariableBase.IsDateTime) { return v.CurrentDateTimeValue.ToString(); } if (v.VariableBase.IsNumber) { return v.CurrentNumberValue.ToString(); } if (v.VariableBase.IsString) { return v.CurrentStringValue.ToString(); } if (v.VariableBase.IsItem) { return (v.CurrentItemValue != null ? v.CurrentItemValue.CurrentName : "NULL ITEM"); } } return res; })); }