Exemple #1
0
        private bool LinkToScriptAssembly(Assembly assembly)
        {
            if (assembly == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(ScriptPath))
            {
                return(false);
            }

            var linker = new BooModuleLinker(assembly, ScriptPath, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            //try to link to callbacks...

            //...but these are disabled since I have no idea how these should work
            //def.OnMaximumCurrency = linker["OnMaximumCurrency"]?.TryCreateDelegate<Action<object>>();
            //def.OnNegativeCurrency = linker["OnNegativeCurrency"]?.TryCreateDelegate<Action<object>>();

            OnLevelUp       = linker["OnLevelUp"]?.TryCreateDelegate <Action <TSPlayer, Class, int> >();
            OnLevelDown     = linker["OnLevelDown"]?.TryCreateDelegate <Action <TSPlayer, Class, int> >();
            OnClassChange   = linker["OnClassChange"]?.TryCreateDelegate <Action <TSPlayer, Class, Class> >();
            OnClassMastered = linker["OnClassMastered"]?.TryCreateDelegate <Action <TSPlayer, Class> >();

            return(true);
        }
        protected override bool OnLinkToScriptAssembly(Assembly ass)
        {
            if (ass == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(ScriptPath))
            {
                return(false);
            }

            var linker = new BooModuleLinker(ass, ScriptPath);

            OnCheckReplace  = linker.TryCreateDelegate <NpcCheckReplaceHandler>("OnCheckReplace");
            OnCheckSpawn    = linker.TryCreateDelegate <NpcCheckSpawnHandler>("OnCheckSpawn");
            OnSpawn         = linker.TryCreateDelegate <NpcSpawnHandler>("OnSpawn");
            OnCollision     = linker.TryCreateDelegate <NpcCollisionHandler>("OnCollision");
            OnTileCollision = linker.TryCreateDelegate <NpcTileCollisionHandler>("OnTileCollision");
            OnTransformed   = linker.TryCreateDelegate <NpcTransformedHandler>("OnTransformed");
            OnKilled        = linker.TryCreateDelegate <NpcKilledHandler>("OnKilled");
            OnStrike        = linker.TryCreateDelegate <NpcStrikeHandler>("OnStrike");
            OnAiUpdate      = linker.TryCreateDelegate <NpcAiUpdateHandler>("OnAiUpdate");

            return(true);
        }
        private void LoadScripts()
        {
            var moduleManager = GetModuleManager();
            var scriptPaths   = GetScriptPaths();

            foreach (var path in scriptPaths)
            {
                moduleManager.Add(path);
            }

            var results = moduleManager.Compile();

            foreach (var cat in Categories.Values)
            {
                foreach (var skill in cat.Values)
                {
                    foreach (var level in skill.Levels)
                    {
                        if (results.TryGetValue(CustomSkillsPlugin.Instance.PluginRelativePath(level.ScriptPath), out var compilerContext))
                        {
                            CustomSkillsPlugin.Instance.LogPrintBooErrors(compilerContext);
                            CustomSkillsPlugin.Instance.LogPrintBooWarnings(compilerContext);

                            if (compilerContext.Errors.Count < 1)
                            {
                                var linker = new BooModuleLinker(compilerContext.GeneratedAssembly, level.ScriptPath);

                                if (level.OnCancelled == null)
                                {
                                    level.OnCancelled = linker.TryCreateDelegate <Action <TSPlayer, SkillState> >("OnCancelled");
                                }

                                if (level.OnLevelUp == null)
                                {
                                    level.OnLevelUp = linker.TryCreateDelegate <Action <TSPlayer> >("OnLevelUp");
                                }

                                if (level.OnCast == null)
                                {
                                    level.OnCast = linker.TryCreateDelegate <Func <TSPlayer, SkillState, bool> >("OnCast");
                                }

                                if (level.OnCharge == null)
                                {
                                    level.OnCharge = linker.TryCreateDelegate <Func <TSPlayer, SkillState, bool> >("OnCharge");
                                }

                                if (level.OnFire == null)
                                {
                                    level.OnFire = linker.TryCreateDelegate <Action <TSPlayer, SkillState> >("OnFire");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void LoadScripts(string scriptPath)
        {
            const string assemblyPrefix = "Banking_";

            if (string.IsNullOrWhiteSpace(scriptPath))
            {
                return;
            }

            if (!File.Exists(scriptPath))
            {
                BankingPlugin.Instance.LogPrint($"Unable to find script file '{scriptPath}'.", TraceLevel.Error);
                return;
            }

            var scriptName   = Path.GetFileNameWithoutExtension(scriptPath);
            var assemblyName = $"{assemblyPrefix}{scriptName}.dll";
            var scripts      = new List <string>()
            {
                scriptPath
            };
            var compiler = new BooScriptCompiler();

            compiler.Configure(ScriptHelpers.GetReferences(),
                               ScriptHelpers.GetDefaultImports(),
                               ScriptHelpers.GetEnsuredMethodSignatures());
            var context = compiler.Compile(assemblyName, scripts);

            if (context.Errors.Count > 0)
            {
                BankingPlugin.Instance.LogPrintBooErrors(context);
                return;
            }
            else if (context.Warnings.Count > 0)
            {
                BankingPlugin.Instance.LogPrintBooWarnings(context);
            }

            var ass    = context.GeneratedAssembly;
            var linker = new BooModuleLinker(ass, scriptPath);

            ScriptOnPreReward       = linker.TryCreateDelegate <Func <string, Reward, CurrencyDefinition, decimal, decimal> >("OnPreReward");
            scriptOnAccountDeposit  = linker.TryCreateDelegate <Action <Bank, BalanceChangedEventArgs> >("OnAccountDeposit");
            scriptOnAccountWithdraw = linker.TryCreateDelegate <Action <Bank, BalanceChangedEventArgs> >("OnAccountWithdraw");
        }
Exemple #5
0
        //internal bool LinkToScript(Assembly assembly)
        protected override bool OnLinkToScriptAssembly(Assembly assembly)
        {
            if (assembly == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(ScriptPath))
            {
                return(false);
            }

            var linker = new BooModuleLinker(assembly, ScriptPath);

            OnSpawn         = linker.TryCreateDelegate <ProjectileSpawnHandler>("OnSpawn");
            OnKilled        = linker.TryCreateDelegate <ProjectileKilledHandler>("OnKilled");
            OnAiUpdate      = linker.TryCreateDelegate <ProjectileAiUpdateHandler>("OnAiUpdate");
            OnGameUpdate    = linker.TryCreateDelegate <ProjectileGameUpdateHandler>("OnGameUpdate");
            OnCollision     = linker.TryCreateDelegate <ProjectileCollisionHandler>("OnCollision");
            OnTileCollision = linker.TryCreateDelegate <ProjectileTileCollisionHandler>("OnTileCollision");

            return(true);
        }
        protected override bool OnLinkToScriptAssembly(Assembly ass)
        {
            if (ass == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(ScriptPath))
            {
                return(false);
            }

            var linker = new BooModuleLinker(ass, ScriptPath);

            OnInvasionStart = linker.TryCreateDelegate <InvasionStartHandler>("OnInvasionStart");
            OnInvasionEnd   = linker.TryCreateDelegate <InvasionEndHandler>("OnInvasionEnd");
            OnUpdate        = linker.TryCreateDelegate <InvasionUpdateHandler>("OnUpdate");
            OnWaveStart     = linker.TryCreateDelegate <InvasionWaveStartHandler>("OnWaveStart");
            OnWaveEnd       = linker.TryCreateDelegate <InvasionWaveEndHandler>("OnWaveEnd");
            OnWaveUpdate    = linker.TryCreateDelegate <InvasionWaveUpdateHandler>("OnWaveUpdate");
            OnBossDefeated  = linker.TryCreateDelegate <InvasionBossDefeatedHandler>("OnBossDefeated");

            return(true);
        }