Beispiel #1
0
        public Item(XmlNode node, Lua lua)
            : this()
        {
            Name        = node.SelectSingleNode("name").InnerText;
            Description = node.SelectSingleNode("desc").InnerText;

            XmlNode field = node.SelectSingleNode("field");

            if (field != null)
            {
                FieldUsage = new FieldUsageRecord();

                FieldUsage.Target = (FieldTarget)Enum.Parse(typeof(FieldTarget), field.SelectSingleNode("@target").Value);

                char targetParameterName = Char.ToLower(FieldUsage.Target.ToString()[0]);

                string canUse = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("canUse").InnerText);
                string use    = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("use").InnerText);

                try
                {
                    FieldUsage.CanUse = (LuaFunction)lua.DoString(canUse).First();
                    FieldUsage.Use    = (LuaFunction)lua.DoString(use).First();
                }
                catch (Exception e)
                {
                    throw new ImplementationException("Error in item field scripts; id = " + ID, e);
                }
            }

            XmlNode battle = node.SelectSingleNode("battle");

            if (battle != null)
            {
                BattleUsage = new BattleUsageRecord();

                BattleUsage.Target = (BattleTarget)Enum.Parse(typeof(BattleTarget), battle.SelectSingleNode("@target").Value);

                XmlNode intendedForEnemiesNode = battle.SelectSingleNode("@intendedForEnemies");

                if (intendedForEnemiesNode != null)
                {
                    BattleUsage.IntendedForEnemies = Boolean.Parse(intendedForEnemiesNode.Value);
                }

                string use = String.Format("return function (s, t) {0} end", battle.SelectSingleNode("use").InnerText);

                try
                {
                    BattleUsage.Use = (LuaFunction)lua.DoString(use).First();
                }
                catch (Exception e)
                {
                    throw new ImplementationException("Error in item battle scripts; id = " + ID, e);
                }
            }
        }
Beispiel #2
0
        public Item(XmlNode node, Lua lua)
            : this()
        {
            Name = node.SelectSingleNode("name").InnerText;
            Description = node.SelectSingleNode("desc").InnerText;

            XmlNode field = node.SelectSingleNode("field");

            if (field != null)
            {
                FieldUsage = new FieldUsageRecord();

                FieldUsage.Target = (FieldTarget)Enum.Parse(typeof(FieldTarget), field.SelectSingleNode("@target").Value);

                char targetParameterName = Char.ToLower(FieldUsage.Target.ToString()[0]);

                string canUse = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("canUse").InnerText);
                string use = String.Format("return function ({0}) {1} end", targetParameterName, field.SelectSingleNode("use").InnerText);

                try
                {
                    FieldUsage.CanUse = (LuaFunction)lua.DoString(canUse).First();
                    FieldUsage.Use = (LuaFunction)lua.DoString(use).First();
                }
                catch (Exception e)
                {
                    throw new ImplementationException("Error in item field scripts; id = " + ID, e);
                }
            }

            XmlNode battle = node.SelectSingleNode("battle");

            if (battle != null)
            {
                BattleUsage = new BattleUsageRecord();

                BattleUsage.Target = (BattleTarget)Enum.Parse(typeof(BattleTarget), battle.SelectSingleNode("@target").Value);

                XmlNode intendedForEnemiesNode = battle.SelectSingleNode("@intendedForEnemies");

                if (intendedForEnemiesNode != null)
                {
                    BattleUsage.IntendedForEnemies = Boolean.Parse(intendedForEnemiesNode.Value);
                }

                string use = String.Format("return function (s, t) {0} end", battle.SelectSingleNode("use").InnerText);

                try
                {
                    BattleUsage.Use = (LuaFunction)lua.DoString(use).First();
                }
                catch (Exception e)
                {
                    throw new ImplementationException("Error in item battle scripts; id = " + ID, e);
                }
            }
        }