Esempio n. 1
0
    string BuildBuyString()
    {
        string result = "[font:uidialoglilspace][linespacing:11]";

        DynValue[] itemName, itemInfo, itemPrice;
        try {
            itemName  = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(1).Table);
            itemInfo  = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(2).Table);
            itemPrice = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(3).Table);
        } catch { throw new CYFException("The variable \"buylist\" must contain a table!"); }

        mainName  = new string[itemName.Length];
        mainInfo  = new DynValue[itemName.Length];
        mainPrice = new int[itemName.Length];

        for (int i = 0; i < itemName.Length; i++)
        {
            if (i < itemPrice.Length && itemPrice[i].Type != DataType.Number && itemPrice[i].Number % 1 != 0)
            {
                throw new CYFException("The price table must contain integers.");
            }
            if (!Inventory.NametoDesc.Keys.Contains(itemName[i].String))
            {
                throw new CYFException("The item \"" + itemName[i].String + "\" doesn't exist in the inventory database.");
            }
            mainName[i]  = itemName[i].String;
            mainInfo[i]  = i >= itemInfo.Length ? DynValue.NewString(Inventory.NametoDesc[itemName[i].String]) : itemInfo[i];
            mainPrice[i] = i >= itemPrice.Length ? Inventory.NametoPrice[mainName[i]] : (int)itemPrice[i].Number;
            try {
                if (mainPrice[i] == -1)
                {
                    mainPrice[i] = Inventory.NametoPrice[mainName[i]];
                }
                if (mainPrice[i] == 0)
                {
                    result += "  [color:808080]--- SOLD OUT ---[color:ffffff]\n";
                }
                else
                {
                    result += "  " + mainPrice[i] + "G - " + mainName[i] + "\n";
                }
            } catch { throw new CYFException("The item \"" + mainName[i] + "\" doesn't have a price in the database."); }
        }
        return(result + "  Exit");
    }
Esempio n. 2
0
 public DynValue Call(Script caller, string function, DynValue[] args = null, bool checkExist = false)
 {
     if (script.Globals[function] == null || script.Globals.Get(function) == null)
     {
         if (checkExist && !GlobalControls.retroMode)
         {
             UnitaleUtil.DisplayLuaError(scriptname, "Attempted to call the function \"" + function + "\", but it didn't exist.");
         }
         //Debug.LogWarning("Attempted to call the function " + function + " but it didn't exist.");
         return(DynValue.Nil);
     }
     if (args != null)
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function], args); }
         catch (Exception e) {
             if (args[0].Type == DataType.Table && args.Length == 1)
             {
                 DynValue[] argsNew = UnitaleUtil.TableToDynValueArray(args[0].Table);
                 try { d = script.Call(script.Globals[function], argsNew); }
                 catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                                                               ex.Message :
                                                                               ex.DecoratedMessage.Substring(5).Contains("chunk_") ?
                                                                               ex.Message :
                                                                               ex.DecoratedMessage); }
                 catch (Exception ex) {
                     if (!GlobalControls.retroMode)
                     {
                         UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
                     }
                 }
             }
             else if (e.GetType() == typeof(InterpreterException) || e.GetType().BaseType == typeof(InterpreterException) || e.GetType().BaseType.BaseType == typeof(InterpreterException))
             {
                 UnitaleUtil.DisplayLuaError(scriptname, ((InterpreterException)e).DecoratedMessage == null ?
                                             ((InterpreterException)e).Message :
                                             ((InterpreterException)e).DecoratedMessage.Substring(5).Contains("chunk_") ?
                                             ((InterpreterException)e).Message :
                                             ((InterpreterException)e).DecoratedMessage);
             }
             else if (!GlobalControls.retroMode)
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + e.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + e.Message + "\n\n" + e.StackTrace + "\n");
             }
         }
         return(d);
     }
     else
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function]); }
         catch (InterpreterException ex) {
             UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                         ex.Message :
                                         ex.DecoratedMessage.Substring(5).Contains("chunk_") ?
                                         ex.Message :
                                         ex.DecoratedMessage);
         } catch (Exception ex) {
             if (!GlobalControls.retroMode)
             {
                 // Special case for infinite loop...
                 if (ex.GetType().ToString() == "System.IndexOutOfRangeException" && ex.StackTrace.StartsWith("  at (wrapper stelemref) object:stelemref (object,intptr,object)"
                                                                                                              + "\r\n  at MoonSharp.Interpreter.DataStructs.FastStack`1[MoonSharp.Interpreter.DynValue].Push (MoonSharp.Interpreter.DynValue item) [0x00001] in"))
                 {
                     UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "<b>Possible infinite loop</b>\n\nThis is a " + ex.GetType() + " error.\n\n"
                                                 + "You almost definitely have an infinite loop in your code. A function tried to call itself infinitely. It could be a normal function or a metatable function."
                                                 + "\n\n\nFull stracktrace (see CYF output log at <b>" + Application.persistentDataPath + "/output_log.txt</b>):\n\n" + ex.StackTrace);
                 }
                 else
                 {
                     UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
                 }
             }
         }
         return(d);
     }
 }
Esempio n. 3
0
    string BuildBuyString()
    {
        string result = "";

        DynValue[] itemName, itemInfo, itemPrice;
        try {
            itemName  = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(1).Table);
            itemInfo  = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(2).Table);
            itemPrice = UnitaleUtil.TableToDynValueArray(script.GetVar("buylist").Table.Get(3).Table);
        } catch {
            UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The variable \"buylist\" must contain a table!");
            return("");
        }
        if (itemPrice.Length == 0)
        {
            UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The variable \"buylist\" must contain a table that contains two tables!");
            return("");
        }
        if (itemName.Length != itemPrice.Length)
        {
            UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The two tables contained in the variable \"buylist\" must have the same size!");
            return("");
        }
        mainName  = new string[itemName.Length];
        mainInfo  = new DynValue[itemName.Length];
        mainPrice = new int[itemName.Length];

        //Permits to align the hyphens

        /*int maxLength = 0;
         * int[] lengths = new int[itemsPrice.Length];
         * for (int i = 0; i < itemsPrice.Length; i ++) {
         *  int length = 1; double number = itemsPrice[i].Number;
         *  while (number >= 10) {
         *      length++;
         *      number = number / 10;
         *  }
         *  if (maxLength < length)
         *      maxLength = length;
         *  lengths[i] = length;
         * }*/

        for (int i = 0; i < itemName.Length; i++)
        {
            if (itemPrice[i].Type != DataType.Number && itemPrice[i].Number % 1 != 0)
            {
                UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The second table must contain integers.");
                return("");
            }
            if (!Inventory.NametoDesc.Keys.Contains(itemName[i].String))
            {
                UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The item \"" + itemName[i].String + "\" doesn't exist in the inventory database.");
                return("");
            }
            //Permits to align the hyphens 2nd part

            /*for (int j = lengths[i]; j < maxLength; j++)
             *  result += "  ";*/
            mainName[i]  = itemName[i].String;
            mainInfo[i]  = itemInfo[i];
            mainPrice[i] = (int)itemPrice[i].Number;
            try {
                if (mainPrice[i] == -1)
                {
                    mainPrice[i] = Inventory.NametoPrice[mainName[i]];
                }
                result += "      " + mainPrice[i] + "G - " + mainName[i] + "\n";
            } catch {
                UnitaleUtil.DisplayLuaError("Creating the Buy menu", "The item \"" + mainName[i] + "\" doesn't have a price in the database.");
                return("");
            }
        }
        return(result + "      Exit");
    }
Esempio n. 4
0
 public DynValue Call(Script caller, string function, DynValue[] args = null, bool checkExist = false)
 {
     if (script.Globals[function] == null || script.Globals.Get(function) == null)
     {
         if (checkExist && !GlobalControls.retroMode)
         {
             UnitaleUtil.DisplayLuaError(scriptname, "Attempted to call the function " + function + " but it didn't exist.");
         }
         //Debug.LogWarning("Attempted to call the function " + function + " but it didn't exist.");
         return(DynValue.Nil);
     }
     if (args != null)
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function], args); }
         catch (Exception e) {
             if (args[0].Type == DataType.Table && args.Length == 1)
             {
                 DynValue[] argsNew = UnitaleUtil.TableToDynValueArray(args[0].Table);
                 try { d = script.Call(script.Globals[function], argsNew); }
                 catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                                                               ex.Message :
                                                                               ex.DecoratedMessage.Substring(5).Contains("chunk_") ?
                                                                               ex.Message :
                                                                               ex.DecoratedMessage); }
                 catch (Exception ex) {
                     if (!GlobalControls.retroMode)
                     {
                         UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
                     }
                 }
             }
             else if (e.GetType() == typeof(InterpreterException) || e.GetType().BaseType == typeof(InterpreterException) || e.GetType().BaseType.BaseType == typeof(InterpreterException))
             {
                 UnitaleUtil.DisplayLuaError(scriptname, ((InterpreterException)e).DecoratedMessage == null ?
                                             ((InterpreterException)e).Message :
                                             ((InterpreterException)e).DecoratedMessage.Substring(5).Contains("chunk_") ?
                                             ((InterpreterException)e).Message :
                                             ((InterpreterException)e).DecoratedMessage);
             }
             else if (!GlobalControls.retroMode)
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + e.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + e.Message + "\n\n" + e.StackTrace + "\n");
             }
         }
         return(d);
     }
     else
     {
         DynValue d = DynValue.Nil;
         try { d = script.Call(script.Globals[function]); }
         catch (InterpreterException ex) {
             UnitaleUtil.DisplayLuaError(scriptname, ex.DecoratedMessage == null ?
                                         ex.Message :
                                         ex.DecoratedMessage.Substring(5).Contains("chunk_") ?
                                         ex.Message :
                                         ex.DecoratedMessage);
         } catch (Exception ex) {
             if (!GlobalControls.retroMode)
             {
                 UnitaleUtil.DisplayLuaError(scriptname + ", calling the function " + function, "This is a " + ex.GetType() + " error. Contact the dev and show him this screen, this must be an engine-side error.\n\n" + ex.Message + "\n\n" + ex.StackTrace + "\n");
             }
         }
         return(d);
     }
 }