/// <summary> /// Calls a function by its number /// </summary> /// <param name="functionNumber"> /// The number of the function /// </param> /// <param name="self"> /// The self. /// </param> /// <param name="caller"> /// The caller. /// </param> /// <param name="target"> /// The target. /// </param> /// <param name="arguments"> /// The arguments. /// </param> /// <returns> /// </returns> public bool CallFunction( int functionNumber, INamedEntity self, INamedEntity caller, IInstancedEntity target, MessagePackObject[] arguments) { FunctionPrototype func = this.GetFunctionByNumber(functionNumber); if (func != null) { if (Program.DebugGameFunctions) { LogUtil.Debug("Called " + func.GetType().Name + ": "); LogUtil.Debug(FunctionArgumentList.List(arguments)); } return(func.Execute(self, caller, target, arguments)); } if (Program.DebugGameFunctions) { LogUtil.Debug("Function " + (FunctionType)functionNumber + "(" + functionNumber + ")" + " not found!"); LogUtil.Debug(FunctionArgumentList.List(arguments)); } return(false); }
/// <summary> /// </summary> /// <returns> /// </returns> public bool ReadFunctions() { try { this.assembly = Assembly.GetExecutingAssembly(); foreach (Type t in this.assembly.GetTypes() .Where( x => x.IsClass && (x.Namespace == "ZoneEngine.Core.Functions.GameFunctions") && ((x.Name != "FunctionPrototype") && (x.Name != "FunctionCollection")))) { { FunctionPrototype temp = (FunctionPrototype)this.assembly.CreateInstance(t.FullName); if (temp == null) { throw new NullReferenceException("Could not create function " + t.FullName); } this.functions.Add(temp.ReturnNumber(), temp); } } } catch (MissingMethodException) { return(false); } catch (FileNotFoundException) { return(false); } catch (FileLoadException) { return(false); } return(true); }