Exemple #1
0
        /// <summary>
        /// Gets the local floating-point value assigned to a specific variable.
        /// </summary>
        /// <param name="name">the variable name</param>
        /// <returns></returns>
        public float GetLocalFloatVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_10_FLOAT)
            {
                PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Local floating-point variable ");
                    sb.Append(name);
                    sb.Append(" was never set.");
                }
                catch (PooledException e)
                {
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                sb.ReturnToPool();
                sb = null;
                throw ex;
            }
            return(svar.Fval);
        }
Exemple #2
0
        /// Gets the local text array value assigned to a specific variable.
        /// </summary>
        /// <param name="name">the variable name</param>
        /// <returns></returns>
        public string[] GetLocalStringArrayVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_09_TEXT_ARR)
            {
                PooledStringBuilder sb =
                    StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Local string array variable ");
                    sb.Append(name);
                    sb.Append(" was never set.");
                }
                catch (PooledException e)
                {
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM,
                                                   sb.ToString());
                sb.ReturnToPool();
                throw ex;
            }
            return(svar.Textaval);
        }
 /// <summary>
 /// Sets the reference id of the item the <see cref="IOCharacter"/> has equipped at a specific equipment slot.
 /// </summary>
 /// <param name="slot">the equipment slot</param>
 /// <param name="item">the item being equipped</param>
 public void SetEquippedItem(int slot, BaseInteractiveObject item)
 {
     if (slot < 0 ||
         slot >= equippedItems.Length)
     {
         PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
         try
         {
             sb.Append("Error - equipment slot ");
             sb.Append(slot);
             sb.Append(" is outside array bounds.");
         }
         catch (PooledException e)
         {
             throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
         }
         RPGException ex = new RPGException(ErrorMessage.BAD_PARAMETERS, sb.ToString());
         sb.ReturnToPool();
         throw ex;
     }
     if (item == null)
     {
         equippedItems[slot] = -1;
     }
     else
     {
         equippedItems[slot] = item.RefId;
         UnityEngine.Debug.Log("putting item " + item.RefId + " in slot " + slot);
     }
 }
Exemple #4
0
        /// <summary>
        /// Gets the local integer array value assigned to a specific variable.
        /// </summary>
        /// <param name="name"> the variable name</param>
        /// <returns></returns>
        public int[] GetLocalIntArrayVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_13_INT_ARR)
            {
                PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                sb.Append("Local floating-point variable ");
                sb.Append(name);
                sb.Append(" was never set.");
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                sb.ReturnToPool();
                throw ex;
            }
            return(svar.Iaval);
        }
 /**
  * Validates the variable type.
  * @ if the type is invalid
  */
 private void ValidateType()
 {
     if (type < ScriptConsts.TYPE_G_00_TEXT ||
         type > ScriptConsts.TYPE_L_15_LONG_ARR)
     {
         PooledStringBuilder sb =
             StringBuilderPool.Instance.GetStringBuilder();
         try
         {
             sb.Append("Invalid ScriptVariable type - ");
             sb.Append(type);
             sb.Append(".");
         }
         catch (PooledException ex)
         {
             throw new RPGException(ErrorMessage.INTERNAL_ERROR, ex);
         }
         RPGException re = new RPGException(ErrorMessage.BAD_PARAMETERS, sb.ToString());
         sb.ReturnToPool();
         throw re;
     }
 }
 /// <summary>
 /// Sets the reference id of the item the <see cref="IOCharacter"/> has equipped at a specific equipment slot.
 /// </summary>
 /// <param name="slot">the equipment slot</param>
 /// <param name="id">the item's reference id</param>
 public void SetEquippedItem(int slot, int id)
 {
     if (slot < 0 ||
         slot >= equippedItems.Length)
     {
         PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
         try
         {
             sb.Append("Error - equipment slot ");
             sb.Append(slot);
             sb.Append(" is outside array bounds.");
         }
         catch (PooledException e)
         {
             throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
         }
         RPGException ex = new RPGException(ErrorMessage.BAD_PARAMETERS, sb.ToString());
         sb.ReturnToPool();
         throw ex;
     }
     equippedItems[slot] = id;
 }
Exemple #7
0
 /// <summary>
 /// Sets a local <see cref="ScriptVariable"/>.
 /// </summary>
 /// <param name="index">the index of the variable</param>
 /// <param name="svar">the local <see cref="ScriptVariable"/></param>
 public void SetLocalVariable(int index, ScriptVariable svar)
 {
     // if the index number is valid
     if (index >= 0)
     {
         // if the local variables array needs to be extended, do so
         if (index >= lvar.Length)
         {
             lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
         }
         else
         {
             lvar[index] = svar;
         }
     }
     else
     {
         PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
         try
         {
             sb.Append("Invalid array index ");
             sb.Append(index);
             sb.Append(".");
         }
         catch (PooledException e)
         {
             sb.ReturnToPool();
             sb = null;
             throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
         }
         RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
         sb.ReturnToPool();
         sb = null;
         throw ex;
     }
 }
Exemple #8
0
 public RPGException(ErrorMessage message, String devMsg, Exception ex) : base(RPGException.GetMessageString(message, devMsg), ex)
 {
     errorMessage     = message;
     developerMessage = ex.Message;
 }
Exemple #9
0
 public RPGException(ErrorMessage message, String devMsg) : base(RPGException.GetMessageString(message, devMsg))
 {
     errorMessage     = message;
     developerMessage = devMsg;
 }
        /**
         * Sets the value the <see cref="ScriptVariable"/> references.
         * @param value the floating-point array value to set
         * @ if the type is invalid
         */
        public void Set(Object value)
        {
            bool throwException = false;

            switch (type)
            {
            case ScriptConsts.TYPE_G_00_TEXT:
            case ScriptConsts.TYPE_L_08_TEXT:
                if (value == null)
                {
                    text = null;
                }
                else
                {
                    text = value.ToString();
                }
                break;

            case ScriptConsts.TYPE_G_01_TEXT_ARR:
            case ScriptConsts.TYPE_L_09_TEXT_ARR:
                if (value == null)
                {
                    textaval = new string[0];
                }
                else if (value is string)
                {
                    textaval = new string[] { value.ToString() };
                }
                else if (value is string[])
                {
                    textaval = new string[((String[])value).Length];
                    Array.Copy((String[])value, textaval, textaval.Length);
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_02_FLOAT:
            case ScriptConsts.TYPE_L_10_FLOAT:
                if (value == null)
                {
                    fval = 0;
                }
                else if (value is float ||
                         value is double ||
                         value is int)
                {
                    fval = Convert.ToSingle(value);
                }
                else if (value is string)
                {
                    try
                    {
                        fval = float.Parse((String)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_03_FLOAT_ARR:
            case ScriptConsts.TYPE_L_11_FLOAT_ARR:
                if (value == null)
                {
                    faval = new float[0];
                }
                else if (value is float[])
                {
                    faval = (float[])value;
                }
                else
                {
                    if (faval == null)
                    {
                        faval = new float[0];
                    }
                    Array.Resize(ref faval, faval.Length + 1);
                    if (value is float ||
                        value is double ||
                        value is int)
                    {
                        faval[faval.Length - 1] = Convert.ToSingle(value);
                    }
                    else if (value is String)
                    {
                        try
                        {
                            faval[faval.Length - 1] = float.Parse((string)value);
                        }
                        catch (Exception ex)
                        {
                            throwException = true;
                        }
                    }
                    else
                    {
                        throwException = true;
                    }
                }
                break;

            case ScriptConsts.TYPE_G_04_INT:
            case ScriptConsts.TYPE_L_12_INT:
                if (value == null)
                {
                    ival = 0;
                }
                else if (value is float ||
                         value is double ||
                         value is int)
                {
                    ival = Convert.ToInt32(value);
                }
                else if (value is String)
                {
                    try
                    {
                        ival = int.Parse((String)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_05_INT_ARR:
            case ScriptConsts.TYPE_L_13_INT_ARR:
                if (value == null)
                {
                    iaval = new int[0];
                }
                else if (value is int[])
                {
                    iaval = (int[])value;
                }
                else
                {
                    if (iaval == null)
                    {
                        iaval = new int[0];
                    }
                    Array.Resize(ref iaval, iaval.Length + 1);
                    if (value is float ||
                        value is double ||
                        value is int)
                    {
                        iaval[iaval.Length - 1] = Convert.ToInt32(value);
                    }
                    else if (value is String)
                    {
                        try
                        {
                            iaval[iaval.Length - 1] = int.Parse((string)value);
                        }
                        catch (Exception ex)
                        {
                            throwException = true;
                        }
                    }
                    else
                    {
                        throwException = true;
                    }
                }
                break;

            case ScriptConsts.TYPE_G_06_LONG:
            case ScriptConsts.TYPE_L_14_LONG:
                if (value == null)
                {
                    lval = 0L;
                }
                else if (value is float ||
                         value is double ||
                         value is int ||
                         value is long)
                {
                    lval = Convert.ToInt64(value);
                }
                else if (value is String)
                {
                    try
                    {
                        lval = long.Parse((String)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_07_LONG_ARR:
            case ScriptConsts.TYPE_L_15_LONG_ARR:
            default:
                if (value == null)
                {
                    laval = new long[0];
                }
                else if (value is long[])
                {
                    laval = (long[])value;
                }
                else
                {
                    if (laval == null)
                    {
                        laval = new long[0];
                    }
                    Array.Resize(ref laval, laval.Length + 1);
                    if (value is float ||
                        value is double ||
                        value is int ||
                        value is long)
                    {
                        laval[laval.Length - 1] = Convert.ToInt64(value);
                    }
                    else if (value is String)
                    {
                        try
                        {
                            laval[laval.Length - 1] = long.Parse((string)value);
                        }
                        catch (Exception ex)
                        {
                            throwException = true;
                        }
                    }
                    else
                    {
                        throwException = true;
                    }
                }
                break;
            }
            if (throwException)
            {
                PooledStringBuilder sb =
                    StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Invalid value ");
                    sb.Append(value);
                    sb.Append(" for ScriptVariable type - ");
                    sb.Append(type);
                    sb.Append(".");
                }
                catch (PooledException e)
                {
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.BAD_PARAMETERS, sb.ToString());
                sb.ReturnToPool();
                throw ex;
            }
        }
        /**
         * Sets a value in the array the <see cref="ScriptVariable"/> references.
         * @param index the array index
         * @param value the value to set
         * @ if the type is invalid
         */
        public void Set(int index, object value)
        {
            bool throwException = false;

            switch (type)
            {
            case ScriptConsts.TYPE_G_01_TEXT_ARR:
            case ScriptConsts.TYPE_L_09_TEXT_ARR:
                if (textaval == null)
                {
                    textaval = new string[0];
                }
                if (index >= textaval.Length)
                {
                    Array.Resize(ref textaval, index + 1);
                }
                textaval[index] = value.ToString();
                break;

            case ScriptConsts.TYPE_G_03_FLOAT_ARR:
            case ScriptConsts.TYPE_L_11_FLOAT_ARR:
                if (faval == null)
                {
                    faval = new float[0];
                }
                if (index >= faval.Length)
                {
                    Array.Resize(ref faval, index + 1);
                }
                if (value == null)
                {
                    throwException = true;
                }
                else if (value is float ||
                         value is double ||
                         value is int)
                {
                    faval[index] = Convert.ToSingle(value);
                }
                else if (value is string)
                {
                    try
                    {
                        faval[index] = float.Parse((string)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_05_INT_ARR:
            case ScriptConsts.TYPE_L_13_INT_ARR:
                if (iaval == null)
                {
                    iaval = new int[0];
                }
                if (index >= iaval.Length)
                {
                    Array.Resize(ref iaval, index + 1);
                }
                if (value == null)
                {
                    throwException = true;
                }
                else if (value is float ||
                         value is double ||
                         value is int)
                {
                    iaval[index] = Convert.ToInt32(value);
                }
                else if (value is string)
                {
                    try
                    {
                        iaval[index] = int.Parse((string)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            case ScriptConsts.TYPE_G_07_LONG_ARR:
            case ScriptConsts.TYPE_L_15_LONG_ARR:
                if (laval == null)
                {
                    laval = new long[0];
                }
                if (index >= laval.Length)
                {
                    Array.Resize(ref laval, index + 1);
                }
                if (value == null)
                {
                    throwException = true;
                }
                else if (value is float ||
                         value is double ||
                         value is int ||
                         value is long)
                {
                    laval[index] = Convert.ToInt64(value);
                }
                else if (value is String)
                {
                    try
                    {
                        laval[index] = long.Parse((string)value);
                    }
                    catch (Exception ex)
                    {
                        throwException = true;
                    }
                }
                else
                {
                    throwException = true;
                }
                break;

            default:
                throwException = true;
                break;
            }
            if (throwException)
            {
                PooledStringBuilder sb =
                    StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Invalid array ScriptVariable type - ");
                    sb.Append(type);
                    sb.Append(".");
                }
                catch (PooledException e)
                {
                    sb.ReturnToPool();
                    sb = null;
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.BAD_PARAMETERS, sb.ToString());
                sb.ReturnToPool();
                sb = null;
                throw ex;
            }
        }
Exemple #12
0
        /// <summary>
        /// Sets a local variable.
        /// </summary>
        /// <param name="name">he name of the global variable</param>
        /// <param name="value">the variable's value</param>
        public void SetLocalVariable(string name, Object value)
        {
            bool found = false;

            for (int i = 0, len = lvar.Length; i < len; i++)
            {
                ScriptVariable svar = lvar[i];
                if (svar != null &&
                    svar.Name != null &&
                    string.Equals(svar.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    svar.Set(value);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                // create a new variable and add to the global array
                ScriptVariable svar = null;
                if (value is string ||
                    value is char[])
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_08_TEXT,
                                              value);
                }
                else if (value is string[] ||
                         value is char[][])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_09_TEXT_ARR, value);
                }
                else if (value is float)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_10_FLOAT,
                                              value);
                }
                else if (value is Double)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_10_FLOAT,
                                              value);
                }
                else if (value is float[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_11_FLOAT_ARR, value);
                }
                else if (value is int)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_12_INT,
                                              value);
                }
                else if (value is int[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_13_INT_ARR, value);
                }
                else if (value is long)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_14_LONG,
                                              value);
                }
                else if (value is long[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_15_LONG_ARR, value);
                }
                else
                {
                    PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                    try
                    {
                        sb.Append("Local variable ");
                        sb.Append(name);
                        sb.Append(" was passed new value of type ");
                        sb.Append(value.GetType().Name);
                        sb.Append(". Only string, Float, float[], Integer, int[],");
                        sb.Append(" Long, or long[] allowed.");
                    }
                    catch (PooledException e)
                    {
                        throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                    }
                    RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                    sb.ReturnToPool();
                    sb = null;
                    throw ex;
                }
                lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
            }
        }