static Globals()
        {
            mod = NWN2Toolset.NWN2ToolsetMainForm.App.Module;
            repository = mod.Repository;
            items = mod.GetBlueprintCollectionForType(NWN2Toolset.NWN2.Data.Templates.NWN2ObjectType.Item);

            customTlk = new OEIShared.IO.TalkTable.TalkTable();
            customTlk.OpenCustom(OEIShared.Utils.BWLanguages.BWLanguage.English, "alfa_acr02.tlk");

            tdaManager = TwoDAManager.Instance;

            spellschools2da = tdaManager.Get("spellschools");
            nwn2_icons2da = tdaManager.Get("nwn2_icons");
            iprp_spells2da = tdaManager.Get("iprp_spells");

            spells = new NWN2Toolset.NWN2.Rules.CNWSpellArray();
            spells.Load();

            globalItemCollection = NWN2Toolset.NWN2.Data.Blueprints.NWN2GlobalBlueprintManager.GetBlueprintsOfType(NWN2Toolset.NWN2.Data.Templates.NWN2ObjectType.Item);

            iconHash = new Dictionary<string, int>();
            int rowCount = Globals.nwn2_icons2da.RowCount;
            for (int i = 0; i < rowCount; i++)
            {
                string twodaString = Globals.nwn2_icons2da["ICON"][i];
                if (!iconHash.ContainsKey(twodaString))
                {
                    iconHash.Add(twodaString, i);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Read each row from a 2DA file and convert it to a collection of
        /// custom types that are 2DA serializable.
        /// </summary>
        /// <typeparam name="T">Supplies the type to instantiate for each 2DA
        /// row.</typeparam>
        /// <typeparam name="TCollection">Supplies the type of collection to
        /// store the row values into.</typeparam>
        /// <param name="DataFile">Supplies the .2DA data file to read.</param>
        /// <returns>Returns a TCollection containing one T for each row in the
        /// .2DA file.</returns>
        public static TCollection Read2DA <T, TCollection>(TwoDAFile DataFile)
            where T : new()
            where TCollection : ICollection <T>, new()
        {
            TCollection Values       = new TCollection();
            var         ColumnFields = GetColumnFieldInfo(typeof(T));

            //
            // Sweep through each row in the .2DA and assign field values for each .2DA serializable
            // field to a new row object that will be added to the row values collection.
            //

            for (int RowIndex = 0; RowIndex < DataFile.RowCount; RowIndex += 1)
            {
                T Value = Read2DARow <T>(DataFile, RowIndex, ColumnFields);
                Values.Add(Value);
            }

            return(Values);
        }
Example #3
0
        /// <summary>
        /// Read a single row from a 2DA file and convert it to a collection of
        /// custom types that are 2DA serializable.
        /// </summary>
        /// <typeparam name="T">Supplies the type to instantiate for the row.
        /// </typeparam>
        /// <param name="DataFile">Supplies the .2DA data file to read.</param>
        /// <param name="RowIndex">Supplies the .2DA row number to
        /// read.</param>
        /// <param name="ColumnFields">Supplies the column field map which must
        /// be returned by GetColumnFieldInfo().</param>
        /// <returns>Returns a new T representing the .2DA row.<returns>
        public static T Read2DARow <T>(TwoDAFile DataFile, int RowIndex, IEnumerable <ColumnFieldInfo> ColumnFields)
            where T : new()
        {
            T Value = new T();

            //
            // Sweep through each column in the .2DA and assign fields based on
            // the TwoDAColumnAttribute deserialization descriptor assigned to
            // each .2DA deserializable field in the type.
            //

            foreach (TwoDAColumn Column in DataFile.Columns)
            {
                var ColumnInfo = ColumnFields.
                                 Where(x => GetColumnName(x.Field, x.Column) == Column.Title).FirstOrDefault();

                if (ColumnInfo == null)
                {
                    continue;
                }

                object FieldValue = ColumnInfo.Column.Default;
                string RawValue   = Column.LiteralValue(RowIndex);
                Type   ValueType  = ColumnInfo.ValueType;
                bool   IsEnum     = ValueType.IsSubclassOf(typeof(Enum));

                if (ColumnInfo.Column.TalkString)
                {
                    uint TalkIndex;

                    if (uint.TryParse(RawValue, out TalkIndex))
                    {
                        FieldValue = Modules.InfoStore.GetTalkString(TalkIndex);
                    }
                }
                else
                {
                    Type SerializeAs = ColumnInfo.Column.SerializeAs;

                    if (SerializeAs == null)
                    {
                        SerializeAs = ValueType;
                    }

                    if (SerializeAs == typeof(string))
                    {
                        FieldValue = RawValue;
                    }
                    else if (SerializeAs == typeof(int))
                    {
                        int ParsedValue;

                        if (int.TryParse(RawValue, out ParsedValue))
                        {
                            FieldValue = ParsedValue;
                        }

                        if (IsEnum)
                        {
                            FieldValue = Enum.ToObject(ValueType, ParsedValue);
                        }
                    }
                    else if (SerializeAs == typeof(uint))
                    {
                        uint ParsedValue;

                        if (uint.TryParse(RawValue,
                                          System.Globalization.NumberStyles.AllowHexSpecifier,
                                          System.Globalization.CultureInfo.InvariantCulture,
                                          out ParsedValue))
                        {
                            FieldValue = ParsedValue;
                        }

                        if (IsEnum)
                        {
                            FieldValue = Enum.ToObject(ValueType, ParsedValue);
                        }
                    }
                    else if (SerializeAs == typeof(bool))
                    {
                        int  IntValue;
                        bool ParsedValue;

                        if (bool.TryParse(RawValue, out ParsedValue))
                        {
                            FieldValue = ParsedValue;
                        }
                        else if (int.TryParse(RawValue, out IntValue))
                        {
                            FieldValue = (IntValue != 0);
                        }
                    }
                    else if (SerializeAs.IsSubclassOf(typeof(Enum)))
                    {
                        try
                        {
                            FieldValue = Enum.Parse(SerializeAs, RawValue);
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Type " + typeof(T) + " cannot be converted from .2DA row; field " + ColumnInfo.Field.Name + " does not have a convertible type supported by TwoDAReader.Read2DA<T, TCollection>.");
                    }
                }

                //
                // Null field values are not assigned.
                //

                if (FieldValue == null)
                {
                    continue;
                }

                //
                // If necessary, coerce the serialized as type to the field
                // type.
                //

                if (FieldValue.GetType() != ValueType)
                {
                    FieldValue = Convert.ChangeType(FieldValue, ValueType);
                }

                ColumnInfo.SetValue(Value, FieldValue);
            }

            //
            // Assign any index columns.
            //

            var IndexColumns = ColumnFields.Where(x => x.Column.Index);

            foreach (var ColumnInfo in IndexColumns)
            {
                object FieldValue = RowIndex;
                Type   ValueType  = ColumnInfo.ValueType;

                //
                // If necessary, coerce the serialized as type to the field
                // type.
                //

                if (FieldValue.GetType() != ValueType)
                {
                    FieldValue = Convert.ChangeType(FieldValue, ValueType);
                }

                ColumnInfo.SetValue(Value, FieldValue);
            }

            return(Value);
        }
Example #4
0
        /// <summary>
        /// The constructor for the form
        /// </summary>
        /// <param name="filePath">The path to where quests must be saved to and loaded from</param>
        public QuestMain(ref String filePath)
            {
            InitializeComponent();

            this.filePath = filePath;
            extra = new LinkedList<Actor>();
            props = new LinkedList<Actor>();
            triggers = new LinkedList<Actor>();
            debug("Plug-Started");

            comboPri.SelectedIndex = 0;
            comboLang.SelectedIndex = 0;

            this.module = NWN2Toolset.NWN2ToolsetMainForm.App.Module;
            genderBox.SelectedIndex = 0;

            if (nwn2IconsFile == null)
                {
                nwn2IconsFile = TwoDAManager.Instance.Get("nwn2_icons");
                nwn2IconsColumnCollection = nwn2IconsFile.Columns;
                }
            }