Example #1
0
        public Spell(Champion owner, string spellName, byte slot)
        {
            this.owner     = owner;
            this.spellName = spellName;
            this.slot      = slot;

            Inibin inibin;

            if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + ".inibin", out inibin))
            {
                if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + ".inibin", out inibin))
                {
                    if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + ".inibin", out inibin))
                    {
                        Logger.LogCoreError("Couldn't find spell stats for " + spellName);
                        return;
                    }
                }
            }

            var i = 0;

            // Generate cooldown values for each level of the spell
            for (i = 0; i < cooldown.Length; ++i)
            {
                cooldown[i] = inibin.GetValue <float>("SpellData", "Cooldown" + (i + 1));
            }

            castTime = ((1.0f + inibin.GetValue <float>("SpellData", "DelayCastOffsetPercent"))) / 2.0f;

            flags           = inibin.GetValue <int>("SpellData", "Flags");
            castRange       = inibin.GetValue <float>("SpellData", "CastRange");
            projectileSpeed = inibin.GetValue <float>("SpellData", "MissileSpeed");
            coefficient     = inibin.GetValue <float>("SpellData", "Coefficient");
            lineWidth       = inibin.GetValue <float>("SpellData", "LineWidth");

            i = 1;
            while (true)
            {
                string key = "Effect" + (0 + i) + "Level0Amount";
                if (inibin.GetValue <object>("SpellData", key) == null)
                {
                    break;
                }


                List <float> effectValues = new List <float>();
                for (var j = 0; j < 6; ++j)
                {
                    key = "Effect" + (0 + i) + "Level" + (0 + j) + "Amount";
                    effectValues.Add(inibin.GetValue <float>("SpellData", key));
                }

                effects.Add(effectValues);
                ++i;
            }

            targetType = (float)Math.Floor(inibin.GetValue <float>("SpellData", "TargettingType") + 0.5f);


            // This is starting to get ugly. How many more names / paths to go ?
            if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + "Missile.inibin", out inibin))
            {
                if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + "Mis.inibin", out inibin))
                {
                    if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + "Missile.inibin", out inibin))
                    {
                        if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + "Missile.inibin", out inibin))
                        {
                            if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + "Mis.inibin", out inibin))
                            {
                                if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + "Mis.inibin", out inibin))
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            castRange       = inibin.GetValue <float>("SpellData", "CastRange");
            projectileSpeed = inibin.GetValue <float>("SpellData", "MissileSpeed");
            projectileFlags = inibin.GetValue <int>("SpellData", "Flags");
        }
Example #2
0
        public void loadLua(LuaScript script)
        {
            string scriptloc = Config.contentManager.GetSpellScriptPath(owner.getType(), getStringForSlot());

            script.lua.DoString("package.path = 'LuaLib/?.lua;' .. package.path");
            script.lua.RegisterFunction("getOwner", this, typeof(Spell).GetMethod("getOwner"));
            script.lua.RegisterFunction("getOwnerX", owner, typeof(Champion).GetMethod("getX"));
            script.lua.RegisterFunction("getOwnerY", owner, typeof(Champion).GetMethod("getY"));
            script.lua.RegisterFunction("getSpellLevel", this, typeof(Spell).GetMethod("getLevel"));
            script.lua.RegisterFunction("getOwnerLevel", owner.getStats(), typeof(Stats).GetMethod("getLevel"));
            script.lua.RegisterFunction("getChampionModel", owner, typeof(Champion).GetMethod("getModel"));
            script.lua.RegisterFunction("getCastTarget", this, typeof(Spell).GetMethod("getTarget"));

            script.lua.RegisterFunction("getSpellToX", this, typeof(Spell).GetMethod("getX"));
            script.lua.RegisterFunction("getSpellToY", this, typeof(Spell).GetMethod("getY"));
            script.lua.RegisterFunction("getRange", this, typeof(Spell).GetMethod("getRange"));

            script.lua.RegisterFunction("setChampionModel", owner, typeof(Champion).GetMethod("setModel", new Type[] { typeof(string) }));

            script.lua.RegisterFunction("teleportTo", this, typeof(Spell).GetMethod("teleportTo", new Type[] { typeof(float), typeof(float) }));
            script.lua.RegisterFunction("isWalkable", this, typeof(Spell).GetMethod("isWalkable", new Type[] { typeof(float), typeof(float) }));

            script.lua.RegisterFunction("getProjectileSpeed", this, typeof(Spell).GetMethod("isWalkable", new Type[] { typeof(float), typeof(float) }));
            script.lua.RegisterFunction("getCoefficient", this, typeof(Spell).GetMethod("isWalkable", new Type[] { typeof(float), typeof(float) }));


            script.lua.RegisterFunction("getProjectileSpeed", this, typeof(Spell).GetMethod("getProjectileSpeed"));
            script.lua.RegisterFunction("getCoefficient", this, typeof(Spell).GetMethod("getCoefficient"));

            script.lua.RegisterFunction("addProjectile", this, typeof(Spell).GetMethod("addProjectile", new Type[] { typeof(float), typeof(float) }));
            script.lua.RegisterFunction("addProjectileTarget", this, typeof(Spell).GetMethod("addProjectileTarget", new Type[] { typeof(Target) }));

            script.lua.RegisterFunction("getEffectValue", this, typeof(Spell).GetMethod("getEffectValue", new Type[] { typeof(int) }));

            script.lua.RegisterFunction("addParticle", this, typeof(Spell).GetMethod("addParticle", new Type[] { typeof(string), typeof(float), typeof(float) }));
            script.lua.RegisterFunction("addParticleTarget", this, typeof(Spell).GetMethod("addParticleTarget", new Type[] { typeof(string), typeof(Target) }));

            script.lua["BUFFTYPE_TEMPORARY"] = BuffType.BUFFTYPE_TEMPORARY;
            script.lua["BUFFTYPE_ETERNAL"]   = BuffType.BUFFTYPE_ETERNAL;

            script.lua.RegisterFunction("addBuff", this, typeof(Spell).GetMethod("addBuff", new Type[] { typeof(string), typeof(float), typeof(BuffType), typeof(Unit) }));

            /*
             * This have to be in general function, not in spell
             * script.lua.set_function("getTeam", [this](Object * o) { return o->getTeam(); });
             * script.lua.set_function("isDead", [this](Unit * u) { return u->isDead(); });
             */


            //TODO : Add buffs

            /*script.lua.set_function("addMovementSpeedBuff", [this](Unit* u, float amount, float duration) { // expose teleport to lua
             *  Buff* b = new Buff(duration);
             *  b->setMovementSpeedPercentModifier(amount);
             *  u->addBuff(b);
             *  u->getStats().addMovementSpeedPercentageModifier(b->getMovementSpeedPercentModifier());
             * return;
             * });*/

            /*
             * script.lua.set_function("addProjectileCustom", [this](const std::string&name, float projSpeed, float toX, float toY) {
             *  Projectile* p = new Projectile(owner->getMap(), GetNewNetID(), owner->getX(), owner->getY(), lineWidth, owner, new Target(toX, toY), this, projectileSpeed, RAFFile::getHash(name), projectileFlags ? projectileFlags : flags);
             *  owner->getMap()->addObject(p);
             *  owner->getMap()->getGame()->notifyProjectileSpawn(p);
             *
             *  return;
             * });
             *
             * script.lua.set_function("addProjectileTargetCustom", [this](const std::string&name, float projSpeed, Target *t) {
             *  Projectile* p = new Projectile(owner->getMap(), GetNewNetID(), owner->getX(), owner->getY(), lineWidth, owner, t, this, projectileSpeed, RAFFile::getHash(name), projectileFlags ? projectileFlags : flags);
             *  owner->getMap()->addObject(p);
             *  owner->getMap()->getGame()->notifyProjectileSpawn(p);
             *
             *  return;
             * });
             *
             *
             * //For spells that don't require SpawnProjectile, but for which we still need to track the projectile server-side
             *
             * script.lua.set_function("addServerProjectile", [this](float toX, float toY) {
             *  Projectile* p = new Projectile(owner->getMap(), futureProjNetId, owner->getX(), owner->getY(), lineWidth, owner, new Target(toX, toY), this, projectileSpeed, 0, projectileFlags ? projectileFlags : flags);
             *  owner->getMap()->addObject(p);
             *
             *  return;
             * });
             *
             * script.lua.set_function("spellAnimation", [this](const std::string&animation, Unit* u) {
             *  owner->getMap()->getGame()->notifySpellAnimation(u, animation);
             *  return;
             * });
             *
             * // TODO: Set multiple animations
             * script.lua.set_function("setAnimation", [this](const std::string&animation1, const std::string&animation2, Unit* u) {
             *  std::vector < std::pair < std::string, std::string>> animationPairs;
             *  animationPairs.push_back(std::make_pair(animation1, animation2));
             *
             *  owner->getMap()->getGame()->notifySetAnimation(u, animationPairs);
             *  return;
             * });
             *
             * script.lua.set_function("resetAnimations", [this](Unit * u) {
             *  std::vector < std::pair < std::string, std::string>> animationPairs;
             *  owner->getMap()->getGame()->notifySetAnimation(u, animationPairs);
             *  return;
             * });
             *
             * script.lua.set_function("dashTo", [this](Unit * u, float x, float y, float dashSpeed) {
             *  u->dashTo(x, y, dashSpeed);
             *  u->setTargetUnit(0);
             *  owner->getMap()->getGame()->notifyDash(u, x, y, dashSpeed);
             *  return;
             * });
             *
             * script.lua.set_function("getUnitsInRange", [this](Target * t, float range, bool isAlive) {
             *  return owner->getMap()->getUnitsInRange(t, range, isAlive);
             * });
             *
             * script.lua.set_function("getChampionsInRange", [this](Target * t, float range, bool isAlive) {
             *  return owner->getMap()->getChampionsInRange(t, range, isAlive);
             * });
             */
            script.loadScript(scriptloc); //todo: abstract class that loads a lua file for any lua
        }
Example #3
0
        public Spell(Champion owner, string spellName, byte slot)
        {
            this.owner = owner;
            this.spellName = spellName;
            this.slot = slot;

            Inibin inibin;
            if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + ".inibin", out inibin))
            {
                if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + ".inibin", out inibin))
                {
                    if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + ".inibin", out inibin))
                    {
                        Logger.LogCoreError("Couldn't find spell stats for " + spellName);
                        return;
                    }
                }
            }

            var i = 0;
            // Generate cooldown values for each level of the spell
            for (i = 0; i < cooldown.Length; ++i)
            {
                cooldown[i] = inibin.GetValue<float>("SpellData", "Cooldown" + (i + 1));
            }

            castTime = ((1.0f + inibin.GetValue<float>("SpellData", "DelayCastOffsetPercent"))) / 2.0f;

            flags = inibin.GetValue<int>("SpellData", "Flags");
            castRange = inibin.GetValue<float>("SpellData", "CastRange");
            projectileSpeed = inibin.GetValue<float>("SpellData", "MissileSpeed");
            coefficient = inibin.GetValue<float>("SpellData", "Coefficient");
            lineWidth = inibin.GetValue<float>("SpellData", "LineWidth");

            i = 1;
            while (true)
            {
                string key = "Effect" + (0 + i) + "Level0Amount";
                if (inibin.GetValue<object>("SpellData", key) == null)
                    break;


                List<float> effectValues = new List<float>();
                for (var j = 0; j < 6; ++j)
                {
                    key = "Effect" + (0 + i) + "Level" + (0 + j) + "Amount";
                    effectValues.Add(inibin.GetValue<float>("SpellData", key));
                }

                effects.Add(effectValues);
                ++i;
            }

            targetType = (float)Math.Floor(inibin.GetValue<float>("SpellData", "TargettingType") + 0.5f);


            // This is starting to get ugly. How many more names / paths to go ?
            if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + "Missile.inibin", out inibin))
            {
                if (!RAFManager.getInstance().readInibin("DATA/Spells/" + spellName + "Mis.inibin", out inibin))
                {
                    if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + "Missile.inibin", out inibin))
                    {
                        if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + "Missile.inibin", out inibin))
                        {
                            if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/Spells/" + spellName + "Mis.inibin", out inibin))
                            {
                                if (!RAFManager.getInstance().readInibin("DATA/Characters/" + owner.getType() + "/" + spellName + "Mis.inibin", out inibin))
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            castRange = inibin.GetValue<float>("SpellData", "CastRange");
            projectileSpeed = inibin.GetValue<float>("SpellData", "MissileSpeed");
            projectileFlags = inibin.GetValue<float>("SpellData", "Flags");
        }