Esempio n. 1
0
        public static void GenerateDummyAPI(LuaQAPI.LuaQAPI lua)
        {
            lua.DoString("InEditor = true");
            LoadNativeAPI(lua, 0, 0);
            foreach (var m in typeof(ScriptInterface).GetMethods())
            {
                APIAttribute attr = null;
                foreach (Attribute a in m.GetCustomAttributes(false))
                    if (a is APIAttribute) attr = (APIAttribute)a;

                if (attr != null)
                    lua.DoString((attr.Group != null ? attr.Group + "." : "") + m.Name + " = function() end");
            }
        }
Esempio n. 2
0
        public static void LoadNativeAPI(LuaQAPI.LuaQAPI lua, float mapWidth, float mapHeight)
        {
            lua.LoadScript("Constants", @"

            -- CONSTANTS ----------------------------------------------

            MapWidth = " + mapWidth + @"
            MapHeight = " + mapHeight + @"

                ");

            var stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Server.ScriptInterface.LuaNativeAPI.lua"));
            String script = stream.ReadToEnd();
            if (!lua.LoadScript("NativeAPI", script))
                throw new Exception(lua.LastError);

            stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Server.ScriptInterface.Triggers.lua"));
            script = stream.ReadToEnd();
            if (!lua.LoadScript("TriggersAPI", script))
                throw new Exception(lua.LastError);

            foreach (var m in typeof(ScriptInterface).GetNestedTypes())
            {
                APIAttribute attr = null;
                foreach (Attribute a in m.GetCustomAttributes(false))
                    if (a is APIAttribute) attr = (APIAttribute)a;

                if (attr != null && m.IsEnum)
                    lua.ExportEnum(m);
            }
            lua.ExportEnum(typeof(Common.UnitStats));
            lua.ExportEnum(typeof(Orders.OrderType));
            lua.ExportEnum(typeof(Common.DamageType));
            lua.ExportEnum(typeof(Common.ArmorType));
            lua.ExportEnum(typeof(Common.UnitState));
            lua.ExportEnum(typeof(Common.CombatMessage.Activity));
            lua.ExportEnum(typeof(Common.CombatMessage.AbilityError));
            lua.ExportEnum(typeof(Common.CombatMessage.HealType));
        }
Esempio n. 3
0
 public static List<String> GetBuffs(LuaQAPI.LuaQAPI lua)
 {
     return new List<string>(lua.IterateKeys<String>("BuffMethods"));
 }
Esempio n. 4
0
 public static Dictionary<String, Parameter> GetBuffParameters(LuaQAPI.LuaQAPI lua, String method)
 {
     return GetParameters(lua, "BuffMethods", method);
 }
Esempio n. 5
0
 public static Dictionary<String, Parameter> GetAbilityParameters(LuaQAPI.LuaQAPI lua, String method)
 {
     return GetParameters(lua, "AbilityMethods", method);
 }
Esempio n. 6
0
 public static List<String> GetAbilities(LuaQAPI.LuaQAPI lua)
 {
     return new List<string>(lua.IterateKeys<String>("AbilityMethods"));
 }
Esempio n. 7
0
 static Dictionary<String, Parameter> GetParameters(LuaQAPI.LuaQAPI lua, String category, String method)
 {
     Dictionary<String, Parameter> parms = new Dictionary<string, Parameter>();
     foreach (var k in lua.IteratePairs<String, object>(category, method, "Parameters"))
     {
         var d = new Dictionary<String, object>();
         foreach (var k2 in lua.IteratePairs<String, object>(-1)) d.Add(k2.Key, k2.Value);
         Parameter p = null;
         if (d.Count == 0)
             continue;
         if ((string)d["Type"] == "float")
             p = new Parameter
             {
                 Type = typeof(float),
                 DefaultValue = (float)(d.ContainsKey("Default") ? d["Default"] : 0f),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "bool")
             p = new Parameter
             {
                 Type = typeof(bool),
                 DefaultValue = (bool)(d.ContainsKey("Default") ? d["Default"] : false),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "string")
             p = new Parameter
             {
                 Type = typeof(string),
                 DefaultValue = (string)(d.ContainsKey("Default") ? d["Default"] : ""),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "int")
             p = new Parameter
             {
                 Type = typeof(int),
                 DefaultValue = (int)(d.ContainsKey("Default") ? (float)d["Default"] : 0),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "bool")
             p = new Parameter
             {
                 Type = typeof(bool),
                 DefaultValue = (bool)(d.ContainsKey("Default") ? (bool)d["Default"] : false),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "model")
             p = new Parameter
             {
                 Type = typeof(Common.Model),
                 DefaultValue = (Common.Model)(d.ContainsKey("Default") ? d["Default"] : Common.Model.None),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "effect")
             p = new Parameter
             {
                 Type = typeof(Common.Effect),
                 DefaultValue = (Common.Effect)(d.ContainsKey("Default") ? d["Default"] : Common.Effect.None),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         else if ((string)d["Type"] == "unitstats")
             p = new Parameter
             {
                 Type = typeof(Common.UnitStats),
                 DefaultValue = (Common.UnitStats)(d.ContainsKey("Default") ? d["Default"] : Common.UnitStats.MaxHitPoints),
                 Tooltip = (string)(d.ContainsKey("Tooltip") ? d["Tooltip"] : "")
             };
         parms.Add((String)k.Key, p);
     }
     return parms;
 }