/// <summary>
        /// Sets the Values array of <paramref name="outObj"/> based on input values from <paramref name="splitLine"/> appropriate where object type is Container
        /// </summary>
        /// <returns><c>true</c> if values were set without errors, <c>false</c> otherwise. Errors are logged within this method.</returns>
        /// <param name="splitLine">Array of values to parse</param>
        /// <param name="outObj">Object whose Values property should be set</param>
        /// <param name="areaFile">Filename of the area file being parsed, used for error messages</param>
        /// <param name="lineNum">Line number the values came from, used for error messages</param>
        private static bool SetContainerValues(string[] splitLine, ObjectPrototypeData outObj, string areaFile, int lineNum)
        {
            // Segment 1 - Capacity, should be an integer
            int capacity = 0;

            if (!Int32.TryParse(splitLine[0], out capacity))
            {
                // Invalid damage dice number
                throw new ObjectParsingException(String.Format("Error parsing capacity for container object {0} in area {1}: expected an integer but found \"{2}\" on line {3}", outObj.VNUM, areaFile, splitLine[0], lineNum));
            }
            else
            {
                // Store the damage dice number
                outObj.Values[0] = capacity;
            }

            // Segment 2 - Flags, should be a string matching Container flags
            try
            {
                ContainerFlag conFlags = AlphaConversions.ConvertROMAlphaToContainerFlag(splitLine[1]);
                outObj.Values[1] = conFlags;
            }
            catch (ArgumentException e)
            {
                // Invalid extra flags
                throw new ObjectParsingException(String.Format("Error parsing container flags for object {0} in area {1}: invalid weapon flag value \"{2}\" found on line {3}", outObj.VNUM, areaFile, splitLine[1], lineNum), e);
            }

            // Segment 3 - Appears to be unused, but should be an integer
            int unknown = 0;

            if (!Int32.TryParse(splitLine[2], out unknown))
            {
                // Invalid damage dice number
                throw new ObjectParsingException(String.Format("Error parsing unknown value (value #3) for container object {0} in area {1}: expected an integer but found \"{2}\" on line {3}", outObj.VNUM, areaFile, splitLine[2], lineNum));
            }
            else
            {
                // Store the damage dice number
                outObj.Values[2] = unknown;
            }

            // Segment 4 - Maximum weight, should be an integer
            int maxWeight = 0;

            if (!Int32.TryParse(splitLine[3], out maxWeight))
            {
                // Invalid damage dice number
                throw new ObjectParsingException(String.Format("Error parsing maximum weight for container object {0} in area {1}: expected an integer but found \"{2}\" on line {3}", outObj.VNUM, areaFile, splitLine[3], lineNum));
            }
            else
            {
                // Store the damage dice number
                outObj.Values[3] = maxWeight;
            }

            // Segment 5 - Weight multiplier, should be an integer
            int weightMult = 0;

            if (!Int32.TryParse(splitLine[4], out weightMult))
            {
                // Invalid damage dice number
                throw new ObjectParsingException(String.Format("Error parsing weight multiplier for container object {0} in area {1}: expected an integer but found \"{2}\" on line {3}", outObj.VNUM, areaFile, splitLine[4], lineNum));
            }
            else
            {
                // Store the damage dice number
                outObj.Values[4] = weightMult;
            }

            return(true);
        }
Ejemplo n.º 2
0
 public static void ClearContainerFlag(this GameObject obj, ContainerFlag flag)
 {
     obj.SetContainerFlags(obj.GetContainerFlags() & ~flag);
 }