예제 #1
0
        /// <summary>
        /// Executes the script
        /// </summary>
        public ScriptReturnData ExecuteScript()
        {
            srd = new ScriptReturnData();

            var sf = new ScriptFunctions(
                srd, DataPath, PluginsPath, OMOD.GetFramework(), ScriptRunnerFunctions);

            switch (type)
            {
            case ScriptType.obmmScript:
                return(OBMMScriptHandler.Execute(
                           OMOD.GetFramework(), script, DataPath, PluginsPath, ScriptRunnerFunctions));

            case ScriptType.Python:
                throw new NotImplementedException();

            case ScriptType.cSharp:
                DotNetScriptHandler.ExecuteCS(script, sf);
                break;

            case ScriptType.vb:
                DotNetScriptHandler.ExecuteVB(script, sf);
                break;
            }

            return(srd);
        }
예제 #2
0
        private void comboBoxEvent_SelectionChangeCommitted(object sender, EventArgs e)
        {
            Described <ServerEvent> selectedEvent = (Described <ServerEvent>)comboBoxEvent.SelectedItem;

            if (CurrentItem != null)
            {
                CurrentItem.Rule.ServerEvent = selectedEvent;
                UpdateItem(CurrentItem.Rule, listViewRules.SelectedItems[0]);
            }

            labelParameters.Text = ScriptFunctions.GetScript(selectedEvent);
        }
예제 #3
0
 private void SetEvent(ServerEvent serverEvent)
 {
     foreach (Described <ServerEvent> de in comboBoxEvent.Items)
     {
         if (de == serverEvent)
         {
             comboBoxEvent.SelectedItem = de;
             labelParameters.Text       = ScriptFunctions.GetScript(serverEvent);
             break;
         }
     }
 }
예제 #4
0
            public double script(ScriptFunctions sf, ScriptData sd)
            {
                double fixingValue = 0.0;
                double payoff      = 0.0;
                double yield       = 0.0;
                bool   iscalled    = false;
                double discount    = 1.0;
                int    i           = 0;

                double strike = sd.INDEX("strike")[0];

                // Go through all dates //
                for (int t = 0; t < sf.PATHNB(); t++)
                {
                    double k = sf.PATHVALUE(t);
                    if (sf.PATHTIME(t) == sd.TIME("fixing")[i] && (iscalled == false))
                    {
                        fixingValue = sf.PATHVALUE(t);
                        yield       = fixingValue / strike;
                        if (yield > 1.0)
                        {
                            iscalled = true;
                            discount = sf.DISCOUNT(sf.PATHTIME(t));

                            payoff = (1 + sd.INDEX("coupons")[i]) * 100 * discount;
                            sf.INSPOUT("ProbaCall " + i, 1.0);
                            return(payoff);
                        }
                        i++;
                    }
                }

                // if no previous payoff compute last redemption //
                fixingValue = sf.PATHVALUE();
                yield       = fixingValue / strike;
                discount    = sf.DISCOUNT();

                if ((iscalled == false) && (yield < sd.INDEX("barrier")[0]))
                {
                    payoff = yield * 100 * discount;
                    sf.INSPOUT("ProbaDown", 1.0);
                    sf.INSPOUT("AvgDown", yield);
                }
                else
                {
                    payoff = 100.0 * discount;
                    sf.INSPOUT("ProbaMid", 1.0);
                }

                // return payoff  //
                return(payoff);
            }
예제 #5
0
        public static void Register()
        {
            #region Class Function Register
            ScriptObjectTypeFactory.Register(typeof(FieldRequestInfo), "GetFieldValue");

            ScriptObjectTypeFactory.Register(typeof(FieldActionResponse), "AddFieldValue", "AddFieldProps");

            #endregion

            #region Functions
            ScriptFunctions.RegisterFunction("GetEntity", GetEntity);
            #endregion
        }
예제 #6
0
 public void Script(ScriptFunctions sf)
 {
     // C# code goes here
     int PCindex = sf.gm.indexOfPCtoLastUseItem;
     MessageBox.Show("Heal Light Wounds");
     int hp = sf.gm.playerList.PCList[PCindex].pc_hp;
     string name = sf.gm.playerList.PCList[PCindex].CharacterName;
     MessageBox.Show(name + "'s current hit points are " + hp.ToString());
     sf.gm.playerList.PCList[PCindex].pc_hp += 10;
     if (sf.gm.playerList.PCList[PCindex].pc_hp > sf.gm.playerList.PCList[PCindex].pc_hpMax)
     {
         sf.gm.playerList.PCList[PCindex].pc_hp = sf.gm.playerList.PCList[PCindex].pc_hpMax;
     }
     MessageBox.Show("now " + name + "'s current hit points are " + sf.gm.playerList.PCList[PCindex].pc_hp.ToString());
     sf.gm.deleteItemUsedScript = true;
 }
예제 #7
0
        public void AttachScript(string scriptPath)
        {
            this.script = true;

            Scripting.ScriptingLua    luaScript;
            Scripting.ScriptFunctions scriptFunctions;

            luaScript       = new WiccanRede.AI.Scripting.ScriptingLua();
            scriptFunctions = new ScriptFunctions(this);
            luaScript.RegisterFunctions(scriptFunctions);
            Logger.AddImportant("Nacitani a spousteni lua skriptu " + scriptPath);
            luaScript.LoadScript(scriptPath);

            luaScript.RunFunction("Init", new object[] { });
            this.controlMechanism = luaScript;
        }
예제 #8
0
        public void Script(ScriptFunctions sf)
        {
            // C# code goes here
            int PCindex = sf.gm.indexOfPCtoLastUseItem;

            MessageBox.Show("Heal Light Wounds");
            int    hp   = sf.gm.playerList.PCList[PCindex].pc_hp;
            string name = sf.gm.playerList.PCList[PCindex].CharacterName;

            MessageBox.Show(name + "'s current hit points are " + hp.ToString());
            sf.gm.playerList.PCList[PCindex].pc_hp += 10;
            if (sf.gm.playerList.PCList[PCindex].pc_hp > sf.gm.playerList.PCList[PCindex].pc_hpMax)
            {
                sf.gm.playerList.PCList[PCindex].pc_hp = sf.gm.playerList.PCList[PCindex].pc_hpMax;
            }
            MessageBox.Show("now " + name + "'s current hit points are " + sf.gm.playerList.PCList[PCindex].pc_hp.ToString());
            sf.gm.deleteItemUsedScript = true;
        }
예제 #9
0
        void ProcessScriptFunctions(ProjectState state, IO.XmlStream s)
        {
            foreach (XmlNode n in s.Cursor.ChildNodes)
            {
                if (n.Name != "function")
                {
                    continue;
                }

                s.SaveCursor(n);
                var sc = new ScriptFunction(state, s);
                s.RestoreCursor();
                string name_str = sc.ToString();

                if (state.scriptingInterface.Functions.Contains(name_str))
                {
                    Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
                    continue;
                }

                try { ScriptFunctions.Add(name_str, sc); }
                catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
            }
        }
예제 #10
0
            public double script(ScriptFunctions sf, ScriptData sd)
            {
                double bond        = 0.0;
                double put         = 0.0;
                double binaryStrip = 0.0;
                double swap        = 0.0;

                int    i    = 0;
                double time = 0.0;

                double strike       = sd.INDEX("strike")[0];
                double couponBond   = sd.INDEX("couponBond")[0];
                double couponBinary = sd.INDEX("couponBinary")[0];
                double barrierDown  = sd.INDEX("barrierDown")[0];

                double recovery = sd.INDEX("recovery")[0];
                double maturity = sd.ENDTIME("fixing");

                double div       = 0.0;
                double rf        = 0.0;
                double survpb    = 1.0;
                double survpb_m1 = 1.0;
                double vol       = 0.0;
                double s         = 0.0;

                // Go through all dates //
                for (int t = 0; t < sf.PATHNB(); t++)
                {
                    s    = sf.PATHVALUE(t);
                    time = sf.PATHTIME(t);

                    if ((time == sd.TIME("fixing")[i]) && (time != maturity))
                    {
                        bond        = 0.0;
                        put         = 0.0;
                        binaryStrip = 0.0;

                        //bond
                        for (int j = i; j < sd.TIME("fixing").Count - 1; j++)
                        {
                            bond = couponBond * sf.DISCOUNT(sd.TIME("fixing")[j]);
                        }
                        //bond += sf.DISCOUNT(maturity);
                        bond = bond / sf.DISCOUNT(time);
                        sf.INSPOUT("Bond" + i, bond);

                        //pdi
                        vol = sf.VOLATILITY(maturity - time, s);
                        rf  = sf.RISKFREERATE(maturity, time);
                        div = sf.DIVIDENDRATE(maturity, time);

                        put = sf.OPTIONPRICE(maturity, time, barrierDown, s, div, rf, vol, Option.Type.Put);
                        put = put / barrierDown;
                        sf.INSPOUT("PDI" + i, put);

                        // binary strip
                        for (int j = i; j < sd.TIME("fixing").Count - 1; j++)
                        {
                            vol = sf.VOLATILITY(sd.TIME("fixing")[j] - time, s);
                            rf  = sf.RISKFREERATE(maturity, time);
                            div = sf.DIVIDENDRATE(maturity, time);

                            binaryStrip += couponBinary / sf.DISCOUNT(time) * sf.BINARYPRICE(maturity, time, barrierDown, s, div, rf, vol, Option.Type.Call);
                        }
                        sf.INSPOUT("Binary" + i, binaryStrip);

                        // Swap
                        survpb = sf.SURVIVALPB(time);
                        swap  += (survpb_m1 - survpb) * Math.Max(0.0, recovery - bond + binaryStrip - put) * sf.DISCOUNT(time);
                        sf.INSPOUT("CondProba" + i, (survpb_m1 - survpb));
                        survpb_m1 = survpb;

                        i++;
                    }
                }

                sf.INSPOUT("yield ", s);
                // return payoff  //
                return(swap);
            }
예제 #11
0
        static void Main(string[] args)
        {
            // BEFORE you checkout the example:
            // this example is not optimized, it is not intended to be used in production
            // this should be used for understanding how the Framework operates, what it
            // needs, what you can do with it and what it returns

            Framework f = new Framework(); // basic, do this or go home

            string temp      = @"M:\Projects\omod\testDLL\temp";
            string OutputDir = @"M:\Projects\omod\testDLL\output";

            // check if the temp and output dir already exist and delete them if they do
            if (Directory.Exists(temp))
            {
                DeleteDirectory(temp);
            }
            Directory.CreateDirectory(temp);
            if (Directory.Exists(OutputDir))
            {
                DeleteDirectory(OutputDir);
            }
            Directory.CreateDirectory(OutputDir);

            f.SetOBMMVersion(1, 1, 12); // latest official obmm version use this unless you know what you're doing
            f.SetTempDirectory(temp);
            // setting the dll path is mostly used for debugging or if you execute the code from somewhere else
            // better safe than sorry just do this if
            f.SetDLLPath(@"M:\Projects\OMOD-Framework\OMOD-Framework\bin\Release\erri120.OMODFramework.dll");

            // after everything is setup you can go ahead and grap the omod
            OMOD omod = new OMOD(@"M:\Projects\omod\testDLL\Robert Male Body Replacer v52 OMOD-40532-1.omod", ref f);

            // before you run the install script, extract the data files and plugins from the omod
            // ExtractDataFiles will always return something but ExtractPlugins can return null if there is no
            // plugins.crc in the OMOD
            string dataPath    = omod.ExtractDataFiles(); //extracts all data files and returns the path to them
            string pluginsPath = omod.ExtractPlugins();   //extracts all plugins and returns the path to them

            // the interface IScriptRunnerFunctions should be implemented by something that you can pass on
            // as an argument, in this case I created an internal class called ScriptFunctions that implements
            // all functions from the interface
            ScriptFunctions a = new ScriptFunctions();

            // the script runner can execute the script, return the script and/or script type
            ScriptRunner sr = new ScriptRunner(ref omod, a);

            //to get the type:
            //ScriptType scriptType = sr.GetScriptType();

            //to get the entire script without the first byte:
            //String script = sr.GetScript();

            // this will execute the script and return all information about what needs to be installed
            ScriptReturnData srd = sr.ExecuteScript();

            // after the script executed go ahead and do whatever you want with the ScriptReturnData:
            // be sure to check if the installation is canceled or you will run into issues
            if (srd.CancelInstall)
            {
                Console.WriteLine("Installation canceled");
            }

            // just for testing
            bool doPretty = true;

            if (doPretty)
            {
                // if you do not want the raw output but a more 'prettier' version, use this method
                // it will change the ScriptReturnData and will populate the InstallFiles list
                srd.Pretty(true, ref omod, ref pluginsPath, ref dataPath);

                // loop through the whole thing, do note the custom struct
                foreach (InstallFile file in srd.InstallFiles)
                {
                    string s = Path.GetDirectoryName(file.InstallTo);
                    if (!Directory.Exists(Path.Combine(OutputDir, s)))
                    {
                        Directory.CreateDirectory(Path.Combine(OutputDir, s));
                    }
                    File.Move(file.InstallFrom, Path.Combine(OutputDir, file.InstallTo));
                }
            }
            else
            {
                // in the following example I will create two lists, one for all data files and one for all
                // plugins that need to be installed
                // this may seem non-intuitive since the ScriptReturnData should return this list
                // the thing is that you have InstallAll, Install, Ignore and Copy operations
                // the install script in the omod decideds what is best for itself

                List <string> InstallPlugins   = new List <string>();
                List <string> InstallDataFiles = new List <string>();

                // start by checking if you can install all plugins
                if (srd.InstallAllPlugins)
                {
                    // simply get all plugin files from the omod and loop through them
                    // the s.Contains is just a safety check
                    foreach (string s in omod.GetPluginList())
                    {
                        if (!s.Contains("\\"))
                        {
                            InstallPlugins.Add(s);
                        }
                    }
                }
                // if you can't install everything go and check the list called InstallPlugins
                // this list gets populated when InstallAllPlugins is false
                // the Framework comes with two utility functions that helps in creating the temp list:
                // strArrayContains and strArrayRemove
                foreach (string s in srd.InstallPlugins)
                {
                    if (!Framework.strArrayContains(InstallPlugins, s))
                    {
                        InstallPlugins.Add(s);
                    }
                }
                // next up is removing all plugins that are set to be ignored:
                foreach (string s in srd.IgnorePlugins)
                {
                    Framework.strArrayRemove(InstallPlugins, s);
                }
                // last is going through the CopyPlugins list
                // in case you ask why there is a CopyPlugins list and what is does:
                // (it makes more sense with data files but whatever)
                // if the omod has eg this folder structure:
                //
                // installfiles/
                //              Option1/
                //                      Meshes/
                //                      Textures/
                //              Option2/
                //                      Meshes/
                //                      Textures/
                // this is nice for writing the installation script as you kan keep track of what option
                // has what files
                // Authors than call CopyPlugins/Data and move the files from the options folder to
                // the root folder:
                //
                // meshes/
                // textures/
                // installfiles/
                //              Option1/
                //                      Meshes/
                //                      Textures/
                //              Option2/
                //                      Meshes/
                //                      Textures/
                foreach (ScriptCopyDataFile scd in srd.CopyPlugins)
                {
                    // check if the file you want to copy actually exists
                    if (!File.Exists(Path.Combine(pluginsPath, scd.CopyFrom)))
                    {
                        return;
                    }
                    else
                    {
                        // check if the mod author didnt make a mistake
                        if (scd.CopyFrom != scd.CopyTo)
                        {
                            // unlikely but you never know
                            if (File.Exists(Path.Combine(pluginsPath, scd.CopyTo)))
                            {
                                File.Delete(Path.Combine(pluginsPath, scd.CopyTo));
                            }
                            File.Copy(Path.Combine(pluginsPath, scd.CopyFrom), Path.Combine(pluginsPath, scd.CopyTo));
                        }
                        // important to add the file to the temp list or else it will not be installed
                        if (!Framework.strArrayContains(InstallPlugins, scd.CopyTo))
                        {
                            InstallPlugins.Add(scd.CopyTo);
                        }
                    }
                }

                // now do the same for the data files :)
                if (srd.InstallAllData)
                {
                    foreach (string s in omod.GetDataFileList())
                    {
                        InstallDataFiles.Add(s);
                    }
                }
                foreach (string s in srd.InstallData)
                {
                    if (!Framework.strArrayContains(InstallDataFiles, s))
                    {
                        InstallDataFiles.Add(s);
                    }
                }
                foreach (string s in srd.IgnoreData)
                {
                    Framework.strArrayRemove(InstallDataFiles, s);
                }
                foreach (ScriptCopyDataFile scd in srd.CopyDataFiles)
                {
                    if (!File.Exists(Path.Combine(dataPath, scd.CopyFrom)))
                    {
                        return;
                    }
                    else
                    {
                        if (scd.CopyFrom != scd.CopyTo)
                        {
                            // because data files can be in subdirectories we have to check if the folder actually exists
                            string dirName = Path.GetDirectoryName(Path.Combine(dataPath, scd.CopyTo));
                            if (!Directory.Exists(dirName))
                            {
                                Directory.CreateDirectory(dirName);
                            }
                            if (File.Exists(Path.Combine(dataPath, scd.CopyTo)))
                            {
                                File.Delete(Path.Combine(dataPath, scd.CopyTo));
                            }
                            File.Copy(Path.Combine(dataPath, scd.CopyFrom), Path.Combine(dataPath, scd.CopyTo));
                        }
                        if (!Framework.strArrayContains(InstallDataFiles, scd.CopyTo))
                        {
                            InstallDataFiles.Add(scd.CopyTo);
                        }
                    }
                }

                // after everything is done some final checks
                for (int i = 0; i < InstallDataFiles.Count; i++)
                {
                    // if the files have \\ at the start than Path.Combine wont work :(
                    if (InstallDataFiles[i].StartsWith("\\"))
                    {
                        InstallDataFiles[i] = InstallDataFiles[i].Substring(1);
                    }
                    string currentFile = Path.Combine(dataPath, InstallDataFiles[i]);
                    // also check if the file we want to install exists and is not in the 5th dimension eating lunch
                    if (!File.Exists(currentFile))
                    {
                        InstallDataFiles.RemoveAt(i--);
                    }
                }

                for (int i = 0; i < InstallPlugins.Count; i++)
                {
                    if (InstallPlugins[i].StartsWith("\\"))
                    {
                        InstallPlugins[i] = InstallPlugins[i].Substring(1);
                    }
                    string currentFile = Path.Combine(pluginsPath, InstallPlugins[i]);
                    if (!File.Exists(currentFile))
                    {
                        InstallPlugins.RemoveAt(i--);
                    }
                }

                // now install
                for (int i = 0; i < InstallDataFiles.Count; i++)
                {
                    // check if the folder exists before copying
                    string s = Path.GetDirectoryName(InstallDataFiles[i]);
                    if (!Directory.Exists(Path.Combine(OutputDir, s)))
                    {
                        Directory.CreateDirectory(Path.Combine(OutputDir, s));
                    }
                    File.Move(Path.Combine(dataPath, InstallDataFiles[i]), Path.Combine(OutputDir, InstallDataFiles[i]));
                }
                for (int i = 0; i < InstallPlugins.Count; i++)
                {
                    File.Move(Path.Combine(pluginsPath, InstallPlugins[i]), Path.Combine(OutputDir, InstallPlugins[i]));
                }
            }
        }