private void TryUpdateValue() { if (1 == m_ParamNum && m_X.HaveValue) { m_HaveValue = true; object objX = m_X.Value; float x = StoryValueHelper.CastTo <float>(objX); m_Value = (float)Math.Exp(x); } else if (2 == m_ParamNum && m_X.HaveValue && m_Y.HaveValue) { m_HaveValue = true; object objX = m_X.Value; object objY = m_Y.Value; if (objX is int && objY is int) { int x = StoryValueHelper.CastTo <int>(objX); int y = StoryValueHelper.CastTo <int>(objY); m_Value = (int)Math.Pow(x, y); } else { float x = StoryValueHelper.CastTo <float>(objX); float y = StoryValueHelper.CastTo <float>(objY); m_Value = (float)Math.Pow(x, y); } } }
private void TryUpdateValue() { if (m_X.HaveValue && m_Y.HaveValue) { m_HaveValue = true; object objX = m_X.Value; object objY = m_Y.Value; if (objX is string || objY is string) { string x = StoryValueHelper.CastTo <string>(objX); string y = StoryValueHelper.CastTo <string>(objY); m_Value = x + y; } else { if (objX is int && objY is int) { int x = StoryValueHelper.CastTo <int>(objX); int y = StoryValueHelper.CastTo <int>(objY); m_Value = x + y; } else { float x = StoryValueHelper.CastTo <float>(objX); float y = StoryValueHelper.CastTo <float>(objY); m_Value = x + y; } } } }
private void TryUpdateValue() { if (m_X.HaveValue) { m_HaveValue = true; object objX = m_X.Value; float x = StoryValueHelper.CastTo <float>(objX); m_Value = (float)Math.Sin(x); } }
private void TryUpdateValue() { if (m_X.HaveValue && m_Y.HaveValue) { m_HaveValue = true; object objX = m_X.Value; object objY = m_Y.Value; float x = StoryValueHelper.CastTo <float>(objX); float y = StoryValueHelper.CastTo <float>(objY); m_Value = (x > y ? 1 : 0); } }
private void TryUpdateValue() { bool isInt = true; bool canCalc = true; for (int i = 0; i < m_List.Count; i++) { if (m_List[i].HaveValue) { if (!(m_List[i].Value is int)) { isInt = false; } } else { canCalc = false; break; } } if (canCalc) { m_HaveValue = true; if (isInt) { int maxV = int.MinValue; for (int i = 0; i < m_List.Count; i++) { int v = StoryValueHelper.CastTo <int>(m_List[i].Value); if (maxV < v) { maxV = v; } } m_Value = maxV; } else { float maxV = float.MinValue; for (int i = 0; i < m_List.Count; i++) { float v = StoryValueHelper.CastTo <float>(m_List[i].Value); if (maxV < v) { maxV = v; } } m_Value = maxV; } } }
private void TryUpdateValue() { if (m_X.HaveValue) { m_HaveValue = true; object objX = m_X.Value; if (objX is int) { int x = StoryValueHelper.CastTo <int>(objX); m_Value = x; } else { float x = StoryValueHelper.CastTo <float>(objX); m_Value = (int)Math.Round(x); } } }
private void TryUpdateValue() { if (1 == m_ParamNum && m_X.HaveValue) { m_HaveValue = true; object objX = m_X.Value; float x = StoryValueHelper.CastTo <float>(objX); m_Value = (float)Math.Log(x); } else if (2 == m_ParamNum && m_X.HaveValue && m_Y.HaveValue) { m_HaveValue = true; object objX = m_X.Value; object objY = m_Y.Value; float x = StoryValueHelper.CastTo <float>(objX); float y = StoryValueHelper.CastTo <float>(objY); m_Value = (float)Math.Log(x, y); } }
private void TryUpdateValue() { if (m_X.HaveValue && m_Y.HaveValue) { m_HaveValue = true; object objX = m_X.Value; object objY = m_Y.Value; if (objX is string || objY is string) { string x = StoryValueHelper.CastTo <string>(objX); string y = StoryValueHelper.CastTo <string>(objY); m_Value = (x != y ? 1 : 0); } else { int x = (int)Convert.ChangeType(objX, typeof(int)); int y = (int)Convert.ChangeType(objY, typeof(int)); m_Value = (x != y ? 1 : 0); } } }
protected override bool ExecCommand(StoryInstance instance, long delta) { if (m_VarName.StartsWith("@@")) { if (null != instance.GlobalVariables) { if (instance.GlobalVariables.ContainsKey(m_VarName)) { object oval = instance.GlobalVariables[m_VarName]; if (oval is int) { int ov = StoryValueHelper.CastTo <int>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { int v = StoryValueHelper.CastTo <int>(m_Value.Value); ov += v; instance.GlobalVariables[m_VarName] = ov; } else { ++ov; instance.GlobalVariables[m_VarName] = ov; } } else { float ov = StoryValueHelper.CastTo <float>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { float v = StoryValueHelper.CastTo <float>(m_Value.Value); ov += v; instance.GlobalVariables[m_VarName] = ov; } else { ++ov; instance.GlobalVariables[m_VarName] = ov; } } } } } else if (m_VarName.StartsWith("@")) { if (instance.LocalVariables.ContainsKey(m_VarName)) { object oval = instance.LocalVariables[m_VarName]; if (oval is int) { int ov = StoryValueHelper.CastTo <int>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { int v = StoryValueHelper.CastTo <int>(m_Value.Value); ov += v; instance.LocalVariables[m_VarName] = ov; } else { ++ov; instance.LocalVariables[m_VarName] = ov; } } else { float ov = StoryValueHelper.CastTo <float>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { float v = StoryValueHelper.CastTo <float>(m_Value.Value); ov += v; instance.LocalVariables[m_VarName] = ov; } else { ++ov; instance.LocalVariables[m_VarName] = ov; } } } } else if (m_VarName.StartsWith("$")) { if (instance.StackVariables.ContainsKey(m_VarName)) { object oval = instance.StackVariables[m_VarName]; if (oval is int) { int ov = StoryValueHelper.CastTo <int>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { int v = StoryValueHelper.CastTo <int>(m_Value.Value); ov += v; instance.StackVariables[m_VarName] = ov; } else { ++ov; instance.StackVariables[m_VarName] = ov; } } else { float ov = StoryValueHelper.CastTo <float>(oval); if (m_ParamNum > 1 && m_Value.HaveValue) { float v = StoryValueHelper.CastTo <float>(m_Value.Value); ov += v; instance.StackVariables[m_VarName] = ov; } else { ++ov; instance.StackVariables[m_VarName] = ov; } } } } return(false); }
public void Evaluate(StoryInstance instance, StoryMessageHandler handler, object iterator, object[] args) { m_HaveValue = false; m_Object.Evaluate(instance, handler, iterator, args); m_Method.Evaluate(instance, handler, iterator, args); bool canCalc = true; if (!m_Object.HaveValue || !m_Method.HaveValue) { canCalc = false; } if (canCalc) { m_HaveValue = true; object obj = m_Object.Value; string method = m_Method.Value; if (null != obj && !string.IsNullOrEmpty(method)) { object v = 0; IEnumerable list = obj as IEnumerable; if (null != list) { if (method == "orderby" || method == "orderbydesc") { bool desc = method == "orderbydesc"; ObjList results = new ObjList(); IEnumerator enumer = list.GetEnumerator(); while (enumer.MoveNext()) { object val = enumer.Current; results.Add(val); } results.Sort((object o1, object o2) => { object r1 = null; for (int i = 0; i < m_Args.Count; i++) { m_Args[i].Evaluate(instance, handler, o1, args); r1 = m_Args[i].Value; } object r2 = null; for (int i = 0; i < m_Args.Count; i++) { m_Args[i].Evaluate(instance, handler, o2, args); r2 = m_Args[i].Value; } string rs1 = r1 as string; string rs2 = r2 as string; int r = 0; if (null != rs1 && null != rs2) { r = rs1.CompareTo(rs2); } else { float rd1 = StoryValueHelper.CastTo <float>(r1); float rd2 = StoryValueHelper.CastTo <float>(r2); r = rd1.CompareTo(rd2); } if (desc) { r = -r; } return(r); }); v = results; } else if (method == "where") { ObjList results = new ObjList(); IEnumerator enumer = list.GetEnumerator(); while (enumer.MoveNext()) { object val = enumer.Current; object r = null; for (int i = 0; i < m_Args.Count; i++) { m_Args[i].Evaluate(instance, handler, val, args); r = m_Args[i].Value; } if (StoryValueHelper.CastTo <int>(r) != 0) { results.Add(val); } } v = results; } else if (method == "top") { object r = null; for (int i = 0; i < m_Args.Count; i++) { m_Args[i].Evaluate(instance, handler, iterator, args); r = m_Args[i].Value; } int ct = StoryValueHelper.CastTo <int>(r); ObjList results = new ObjList(); IEnumerator enumer = list.GetEnumerator(); while (enumer.MoveNext()) { object val = enumer.Current; if (ct > 0) { results.Add(val); --ct; } } v = results; } } m_Value = v; } else { m_Value = null; } } for (int i = 0; i < m_Args.Count; i++) { m_Args[i].Evaluate(instance, handler, iterator, args); } }
private void TryUpdateValue() { if (m_Object.HaveValue && m_Type.HaveValue) { m_HaveValue = true; var obj = m_Object.Value; var objType = m_Type.Value; try { string str = obj.AsString; string type = objType.IsString ? objType.StringVal : null; if (null != type) { if (obj.IsString) { if (0 == type.CompareTo("sbyte")) { m_Value = StoryValueHelper.CastTo <sbyte>(str); } else if (0 == type.CompareTo("byte")) { m_Value = StoryValueHelper.CastTo <byte>(str); } else if (0 == type.CompareTo("short")) { m_Value = StoryValueHelper.CastTo <short>(str); } else if (0 == type.CompareTo("ushort")) { m_Value = StoryValueHelper.CastTo <ushort>(str); } else if (0 == type.CompareTo("int")) { m_Value = StoryValueHelper.CastTo <int>(str); } else if (0 == type.CompareTo("uint")) { m_Value = StoryValueHelper.CastTo <uint>(str); } else if (0 == type.CompareTo("long")) { m_Value = StoryValueHelper.CastTo <long>(str); } else if (0 == type.CompareTo("ulong")) { m_Value = StoryValueHelper.CastTo <ulong>(str); } else if (0 == type.CompareTo("float")) { m_Value = StoryValueHelper.CastTo <float>(str); } else if (0 == type.CompareTo("double")) { m_Value = StoryValueHelper.CastTo <double>(str); } else if (0 == type.CompareTo("string")) { m_Value = str; } else if (0 == type.CompareTo("bool")) { m_Value = StoryValueHelper.CastTo <bool>(str); } else { Type t = Type.GetType(type); if (null != t) { m_Value = BoxedValue.FromObject(StoryValueHelper.CastTo(t, str)); } else { GameFramework.LogSystem.Warn("null == Type.GetType({0})", type); } } } else { if (0 == type.CompareTo("sbyte")) { m_Value = obj.Get <sbyte>(); } else if (0 == type.CompareTo("byte")) { m_Value = obj.Get <byte>(); } else if (0 == type.CompareTo("short")) { m_Value = obj.Get <short>(); } else if (0 == type.CompareTo("ushort")) { m_Value = obj.Get <ushort>(); } else if (0 == type.CompareTo("int")) { m_Value = obj.Get <int>(); } else if (0 == type.CompareTo("uint")) { m_Value = obj.Get <uint>(); } else if (0 == type.CompareTo("long")) { m_Value = obj.Get <long>(); } else if (0 == type.CompareTo("ulong")) { m_Value = obj.Get <ulong>(); } else if (0 == type.CompareTo("float")) { m_Value = obj.Get <float>(); } else if (0 == type.CompareTo("double")) { m_Value = obj.Get <double>(); } else if (0 == type.CompareTo("decimal")) { m_Value = obj.Get <decimal>(); } else if (0 == type.CompareTo("bool")) { m_Value = obj.Get <bool>(); } else if (0 == type.CompareTo("char")) { m_Value = obj.Get <char>(); } else if (0 == type.CompareTo("string")) { m_Value = obj.Get <string>(); } else { Type t = Type.GetType(type); if (null != t) { m_Value = BoxedValue.FromObject(obj.Get(t)); } else { GameFramework.LogSystem.Warn("null == Type.GetType({0})", type); } } } } else { var t = objType.IsObject ? objType.ObjectVal as Type : null; if (null != t) { m_Value = BoxedValue.From(StoryValueHelper.CastTo(t, obj.GetObject())); } } } catch (Exception ex) { GameFramework.LogSystem.Warn("Exception:{0}\n{1}", ex.Message, ex.StackTrace); m_Value = BoxedValue.NullObject; } } }
private void TryUpdateValue() { if (m_Object.HaveValue && m_Type.HaveValue) { m_HaveValue = true; object obj = m_Object.Value; object objType = m_Type.Value; try { string type = objType as string; if (null != type) { if (0 == type.CompareTo("sbyte")) { m_Value = StoryValueHelper.CastTo <sbyte>(obj); } else if (0 == type.CompareTo("byte")) { m_Value = StoryValueHelper.CastTo <byte>(obj); } else if (0 == type.CompareTo("short")) { m_Value = StoryValueHelper.CastTo <short>(obj); } else if (0 == type.CompareTo("ushort")) { m_Value = StoryValueHelper.CastTo <ushort>(obj); } else if (0 == type.CompareTo("int")) { m_Value = StoryValueHelper.CastTo <int>(obj); } else if (0 == type.CompareTo("uint")) { m_Value = StoryValueHelper.CastTo <uint>(obj); } else if (0 == type.CompareTo("long")) { m_Value = StoryValueHelper.CastTo <long>(obj); } else if (0 == type.CompareTo("ulong")) { m_Value = StoryValueHelper.CastTo <ulong>(obj); } else if (0 == type.CompareTo("float")) { m_Value = StoryValueHelper.CastTo <float>(obj); } else if (0 == type.CompareTo("double")) { m_Value = StoryValueHelper.CastTo <double>(obj); } else if (0 == type.CompareTo("string")) { m_Value = StoryValueHelper.CastTo <string>(obj); } else if (0 == type.CompareTo("bool")) { m_Value = StoryValueHelper.CastTo <bool>(obj); } else { Type t = Type.GetType(type); if (null != t) { m_Value = Convert.ChangeType(obj, t); } else { GameFramework.LogSystem.Warn("null == Type.GetType({0})", type); } } } else { var t = objType as Type; if (null != t) { m_Value = Convert.ChangeType(obj, t); } } } catch (Exception ex) { GameFramework.LogSystem.Warn("Exception:{0}\n{1}", ex.Message, ex.StackTrace); m_Value = null; } } }