コード例 #1
0
 // Double delegate for UDA
 private static double VolumeCalculation(DbElement ele, DbAttribute att, DbQualifier qualifier)
 {
     // Uda calculates the volume by multiplying the lengths along each side
     double x = ele.GetDouble(ATT.XLEN);
     double y = ele.GetDouble(ATT.YLEN);
     double z = ele.GetDouble(ATT.ZLEN);
     // Result of UDA must be returned
     return (x * y * z);
 }
コード例 #2
0
		public override void SetSort(string sortColumn, ListSortDirection dir) {
			try {
				base.SetSort(sortColumn, dir);
				_attributeSortIndex = _list.Attributes.IndexOf(_list.Attributes.FirstOrDefault(p => p.AttributeName == sortColumn || p.DisplayName == sortColumn));

				if (_attributeSortIndex > -1)
					_current = _list.Attributes[_attributeSortIndex];
			}
			catch { }
		}
コード例 #3
0
		public static void SetToolTip(DbAttribute attribute, FrameworkElement label) {
			string description;

			if (!String.IsNullOrEmpty(attribute.Description)) {
				description = attribute.Description;

				TextBlock block = new TextBlock();
				block.Text = description;
				block.TextWrapping = TextWrapping.Wrap;
				block.MaxWidth = 300;
				label.ToolTip = block;
				label.SetValue(ToolTipService.ShowDurationProperty, 30000);
			}
		}
コード例 #4
0
		public bool this[DbAttribute attribute] {
			get { return this[attribute.DisplayName]; }
			set { this[attribute.DisplayName] = value; }
		}
コード例 #5
0
		public void SetAttr(string name)
		{
			Attr = DbAttribute.GetDbAttribute(name);
		}
コード例 #6
0
        public static void ValidateUndo(GDbTabWrapper <TKey, TValue> tab, string text, DbAttribute attribute)
        {
            try {
                if (tab.List.SelectedItem != null && !tab.ItemsEventsDisabled)
                {
                    TValue tuple = (TValue)tab.List.SelectedItem;
                    ITableCommand <TKey, TValue> command = tab.Table.Commands.Last();

                    if (command is ChangeTupleProperty <TKey, TValue> )
                    {
                        ChangeTupleProperty <TKey, TValue> changeCommand = (ChangeTupleProperty <TKey, TValue>)command;
                        IGenericDbCommand last = tab.GenericDatabase.Commands.Last();

                        if (last != null)
                        {
                            if (last is GenericDbCommand <TKey> )
                            {
                                GenericDbCommand <TKey> nLast = (GenericDbCommand <TKey>)last;

                                if (ReferenceEquals(nLast.Table, tab.Table))
                                {
                                    // The last command of the table is being edited

                                    if (changeCommand.Tuple != tuple || changeCommand.Attribute.Index != attribute.Index)
                                    {
                                        //tab.Table.Commands.Set(tuple, attribute, text);
                                    }
                                    else
                                    {
                                        changeCommand.NewValue = text;
                                        changeCommand.Execute(tab.Table);

                                        if (changeCommand.NewValue.ToString() == changeCommand.OldValue.ToString())
                                        {
                                            nLast.Undo();
                                            tab.GenericDatabase.Commands.RemoveCommands(1);
                                            tab.Table.Commands.RemoveCommands(1);
                                        }

                                        return;
                                    }
                                }
                            }
                        }

                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                    else
                    {
                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
コード例 #7
0
		public SelectFromDialog(Table<int, ReadableTuple<int>> table, ServerDbs db, string text) : base("Select item in [" + db.Filename + "]", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) {
			InitializeComponent();
			Extensions.SetMinimalSize(this);

			_unclickableBorder.Init(_cbSubMenu);

			DbAttribute attId = table.AttributeList.PrimaryAttribute;
			DbAttribute attDisplay = table.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? table.AttributeList.Attributes[1];

			Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
					new ListViewDataTemplateHelper.GeneralColumnInfo {Header = attId.DisplayName, DisplayExpression = "[" + attId.Index + "]", SearchGetAccessor = attId.AttributeName, FixedWidth = 60, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + attId.Index + "]"},
					new ListViewDataTemplateHelper.RangeColumnInfo {Header = attDisplay.DisplayName, DisplayExpression = "[" + attDisplay.Index + "]", SearchGetAccessor = attDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + attDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap }
				}, new DatabaseItemSorter(table.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" });

			//_listView.ItemsSource = new ObservableCollection<ReadableTuple<int>>(table.FastItems);

			GTabSettings<int, ReadableTuple<int>> gTabSettings = new GTabSettings<int, ReadableTuple<int>>(db, null);
			gTabSettings.AttributeList = table.AttributeList;
			gTabSettings.AttId = attId;
			gTabSettings.AttDisplay = attDisplay;

			GSearchEngine<int, ReadableTuple<int>> gSearchEngine = new GSearchEngine<int, ReadableTuple<int>>(db, gTabSettings);

			var attributes = new DbAttribute[] { attId, attDisplay }.Concat(table.AttributeList.Attributes.Skip(2).Where(p => p.IsSearchable != null)).ToList();

			if (attributes.Count % 2 != 0) {
				attributes.Add(null);
			}

			gSearchEngine.SetAttributes(attributes);
			gSearchEngine.SetSettings(attId, true);
			gSearchEngine.SetSettings(attDisplay, true);
			gSearchEngine.Init(_gridSearchContent, _searchTextBox, _listView, table);

			_searchTextBox.GotFocus += new RoutedEventHandler(_searchTextBox_GotFocus);
			_searchTextBox.LostFocus += new RoutedEventHandler(_searchTextBox_LostFocus);
			_buttonOpenSubMenu.Click += new RoutedEventHandler(_buttonOpenSubMenu_Click);
			_listView.MouseDoubleClick += new MouseButtonEventHandler(_listView_MouseDoubleClick);

			Loaded += delegate {
				gSearchEngine.Filter(this);
			};

			bool first = true;
			gSearchEngine.FilterFinished += delegate {
				if (!first)
					return;

				try {
					int ival;

					if (Int32.TryParse(text, out ival)) {
						_listView.Dispatch(delegate {
							_listView.SelectedItem = table.TryGetTuple(ival);
							TokeiLibrary.WPF.Extensions.ScrollToCenterOfView(_listView, _listView.SelectedItem);
						});
					}
				}
				finally {
					first = false;
				}
			};
		}
コード例 #8
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySet(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute) {
			builder.Append("\t");
			builder.Append(attribute.AttributeName);
			builder.Append(": ");
			builder.AppendLineUnix(tuple.GetValue<string>(attribute));
		}
コード例 #9
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultBoolean(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue) {
			if (tuple.GetRawValue(attribute.Index) as string == "")
				return;

			bool val = tuple.GetValue<bool>(attribute);

			if (val != defaultValue) {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": ");
				builder.AppendLineUnix(val.ToString().ToLower());
			}
		}
コード例 #10
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultLocation(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute) {
			string val = tuple.GetValue<string>(attribute);

			if (val != "" && val != "0") {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": ");
				builder.AppendLineUnix(val);
			}
		}
コード例 #11
0
 private ClientResourceAttributes(DbAttribute attribute)
     : base(attribute)
 {
     AttributeList.Add(this);
 }
コード例 #12
0
 private ClientItemAttributes(DbAttribute attribute)
     : base(attribute)
 {
     AttributeList.Add(this);
 }
コード例 #13
0
        public GenericFlagDialog(DbAttribute attribute, string text, Type enumType, FlagTypeData flagTypeData, string description) : base(description, "cde.ico", SizeToContent.WidthAndHeight, ResizeMode.CanResize)
        {
            InitializeComponent();

            _value = text.ToLong();

            if (flagTypeData != null)
            {
                List <long> valuesEnum = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).Select(p => p.Value).ToList();
                var         values     = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).ToList();

                GridIndexProvider provider = _findGrid(values);

                var toolTips = new string[values.Count];

                for (int i = 0; i < values.Count; i++)
                {
                    toolTips[i] = _getTooltip(values[i].Description);
                }

                AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count);
                ToolTipsBuilder.Initialize(toolTips, this);

                int row;
                int col;

                for (int i = 0; i < values.Count; i++)
                {
                    provider.Next(out row, out col);

                    int      index = (int)iProvider.Next();
                    CheckBox box   = new CheckBox {
                        Content = values[index].Name, Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center
                    };

                    var      menu = new ContextMenu();
                    MenuItem item = new MenuItem();
                    item.Header     = "Restrict search to [" + values[index].Name + "]";
                    box.ContextMenu = menu;
                    menu.Items.Add(item);
                    item.Click += delegate {
                        var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                        if (selected != null)
                        {
                            selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + "Flags." + values[index].Name + ") != 0";
                        }
                    };

                    box.Tag = valuesEnum[index];
                    WpfUtils.AddMouseInOutEffectsBox(box);
                    _boxes.Add(box);
                    _upperGrid.Children.Add(box);
                    WpfUtilities.SetGridPosition(box, row, 2 * col);
                }

                _boxes.ForEach(_addEvents);
            }
            else
            {
                if (enumType.BaseType != typeof(Enum))
                {
                    throw new Exception("Invalid argument type, excepted an enum.");
                }

                if (enumType == typeof(MobModeType))
                {
                    if (DbPathLocator.GetServerType() == ServerType.RAthena && !ProjectConfiguration.UseOldRAthenaMode)
                    {
                        enumType = typeof(MobModeTypeNew);
                    }
                }

                List <long> valuesEnum = Enum.GetValues(enumType).Cast <int>().Select(p => (long)p).ToList();
                var         values     = Enum.GetValues(enumType).Cast <Enum>().ToList();

                string[] commands = Description.GetAnyDescription(enumType).Split('#');

                if (commands.Any(p => p.StartsWith("max_col_width:")))
                {
                    _maxColWidth = Int32.Parse(commands.First(p => p.StartsWith("max_col_width")).Split(':')[1]);
                }

                GridIndexProvider provider = _findGrid(values);

                var toolTips = new string[values.Count];

                if (!commands.Contains("disable_tooltips"))
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        toolTips[i] = _getTooltip(Description.GetDescription(values[i]));
                    }
                }

                AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count);

                if (commands.Any(p => p.StartsWith("order:")))
                {
                    List <int> order = commands.First(p => p.StartsWith("order:")).Split(':')[1].Split(',').Select(Int32.Parse).ToList();

                    for (int i = 0; i < values.Count; i++)
                    {
                        if (!order.Contains(i))
                        {
                            order.Add(i);
                        }
                    }

                    iProvider = new SpecifiedIndexProvider(order);
                }

                ToolTipsBuilder.Initialize(toolTips, this);

                int        row;
                int        col;
                ServerType currentType = DbPathLocator.GetServerType();

                for (int i = 0; i < values.Count; i++)
                {
                    provider.Next(out row, out col);

                    int      index = (int)iProvider.Next();
                    CheckBox box   = new CheckBox {
                        Content = _getDisplay(Description.GetDescription(values[index])), Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center
                    };
                    ServerType type = _getEmuRestrition(Description.GetDescription(values[index]));

                    if ((type & currentType) != currentType)
                    {
                        box.IsEnabled = false;
                    }

                    var      menu = new ContextMenu();
                    MenuItem item = new MenuItem();
                    item.Header     = "Restrict search to [" + _getDisplay(Description.GetDescription(values[index])) + "]";
                    box.ContextMenu = menu;
                    menu.Items.Add(item);
                    item.Click += delegate {
                        var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                        if (selected != null)
                        {
                            selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + valuesEnum[index] + ") != 0";
                        }
                    };

                    box.Tag = valuesEnum[index];
                    WpfUtils.AddMouseInOutEffectsBox(box);
                    _boxes.Add(box);
                    _upperGrid.Children.Add(box);
                    WpfUtilities.SetGridPosition(box, row, 2 * col);
                }

                _boxes.ForEach(_addEvents);
            }
        }
コード例 #14
0
 public GenericFlagDialog(DbAttribute attribute, string text, Type enumType, FlagTypeData flagTypeData) : this(attribute, text, enumType, flagTypeData, enumType == null ? "Flag edit" : _getDisplay(Description.GetAnyDescription(enumType)))
 {
 }
コード例 #15
0
 public GenericFlagDialog(DbAttribute attribute, string text, Type enumType) : this(attribute, text, enumType, null, _getDisplay(Description.GetAnyDescription(enumType)))
 {
 }
コード例 #16
0
        private void _filterInternal(string currentSearch, Action finished)
        {
            lock (_filterLock) {
                IsFiltering = true;
                bool isCondition = false;

                try {
                    if (currentSearch != _searchItemsFilter)
                    {
                        return;
                    }
                    if (_items == null)
                    {
                        return;
                    }

                    List <TValue> allItems;

                    if (SubsetCondition != null)
                    {
                        allItems = _getItemsFunction().Where(p => SubsetCondition(p)).ToList();
                    }
                    else
                    {
                        allItems = _getItemsFunction();
                    }

                    if (SetupImageDataGetter != null)
                    {
                        allItems.Where(p => p.GetImageData == null).ToList().ForEach(p => SetupImageDataGetter(p));
                    }

                    if (allItems.Count == 0)
                    {
                        _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(new List <TValue>()));
                        _textBoxOk();
                        OnFilterFinished(new List <TValue>());
                        return;
                    }

                    if (!_searchFirstTimeSet)
                    {
                        _entryComparer = new DatabaseItemSorter <TValue>(_settings.AttributeList);
                        _entryComparer.SetSort(_settings.AttId.AttributeName, ListSortDirection.Ascending);
                        _searchFirstTimeSet = true;
                    }

                    _items.Dispatch(p => _entryComparer.SetSort(WpfUtils.GetLastGetSearchAccessor(_items), WpfUtils.GetLastSortDirection(_items)));

                    if (_ignoreFilter)
                    {
                        allItems = allItems.OrderBy(p => p, _entryComparer).ToList();
                        _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(allItems));
                        OnFilterFinished(allItems);
                        _ignoreFilter = false;
                        return;
                    }

                    Condition     condition;
                    List <string> search = _getSearch(currentSearch, out condition);

                    isCondition = search == null;

                    if (search != null && search.Count == 0 &&
                        !_attributes.Where(p => p.DataType.BaseType == typeof(Enum)).Any(p => _itemsSearchSettings[p]) &&
                        !_itemsSearchSettings[GSearchSettings.TupleAdded] &&
                        !_itemsSearchSettings[GSearchSettings.TupleModified] &&
                        !_itemsSearchSettings[GSearchSettings.TupleRange])
                    {
                        allItems = allItems.OrderBy(p => p, _entryComparer).ToList();
                        _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(allItems));
                        _textBoxOk();
                        OnFilterFinished(allItems);
                        return;
                    }

                    if (currentSearch != _searchItemsFilter)
                    {
                        return;
                    }

                    _textBoxProcessing();

                    string predicateSearch = _tbItemsRange.Dispatch(() => _tbItemsRange.Text);
                    bool   isWiden         = _itemsSearchSettings.Get(GSearchSettings.Mode) == "0";

                    List <Func <TValue, string, bool> > generalPredicates =
                        (from attribute in _attributes
                         where attribute != null
                         let attributeCopy = attribute
                                             where _itemsSearchSettings[attributeCopy]
                                             where attribute.DataType.BaseType != typeof(Enum)
                                             select new Func <TValue, string, bool>((p, s) => p.GetValue <string>(attributeCopy).IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1)).ToList();

                    bool isAttributeRestricted = false;

                    if (search == null)
                    {
                        _textBoxPrediate();
                        generalPredicates.Clear();
                        var predicate = condition.ToPredicate(_settings);
                        generalPredicates = new List <Func <TValue, string, bool> > {
                            predicate
                        };
                    }
                    else if (search.Any(p => p.StartsWith("[", StringComparison.Ordinal) && p.EndsWith("]", StringComparison.Ordinal)))
                    {
                        generalPredicates.Clear();

                        for (int index = 0; index < search.Count; index++)
                        {
                            string se = search[index];
                            int    ival;

                            if (se.StartsWith("[", StringComparison.Ordinal) && se.EndsWith("]", StringComparison.Ordinal))
                            {
                                se = se.Substring(1, se.Length - 2);
                                se = se.Replace("_", " ");
                                var att = _settings.AttributeList.Attributes.FirstOrDefault(p => p.DisplayName.IndexOf(se, 0, StringComparison.OrdinalIgnoreCase) > -1);

                                if (Int32.TryParse(se, out ival) || att != null)
                                {
                                    if (ival < _settings.AttributeList.Attributes.Count)
                                    {
                                        DbAttribute attribute = att ?? _settings.AttributeList.Attributes[ival];
                                        isAttributeRestricted = true;
                                        //generalPredicates.Add(new Func<TValue, string, bool>((p, s) => p.GetValue<string>(attribute).IndexOf(s, StringComparison.OrdinalIgnoreCase) != -1));
                                        string nextSearch = index + 1 < search.Count ? search[index + 1] : "";
                                        generalPredicates.Add(new Func <TValue, string, bool>((p, s) => String.Compare(p.GetValue <string>(attribute), nextSearch, StringComparison.OrdinalIgnoreCase) == 0));
                                    }
                                    search.RemoveAt(index);
                                    index--;
                                }
                            }
                        }
                    }

                    List <DbAttribute> enumAttributes = _attributes.Where(p => p.DataType.BaseType == typeof(Enum) && _itemsSearchSettings[p]).ToList();

                    bool hasTuplePredicates = _itemsSearchSettings[GSearchSettings.TupleAdded] ||
                                              _itemsSearchSettings[GSearchSettings.TupleModified] ||
                                              _itemsSearchSettings[GSearchSettings.TupleRange] ||
                                              enumAttributes.Any();

                    Func <TValue, bool> tuplePredicate = null;

                    if (hasTuplePredicates)
                    {
                        tuplePredicate = _getTuplePredicates(enumAttributes, predicateSearch);
                    }
                    if (currentSearch != _searchItemsFilter)
                    {
                        return;
                    }

                    List <TValue> result = _getResults(search, isAttributeRestricted, generalPredicates, allItems, tuplePredicate, isWiden);

                    if (currentSearch != _searchItemsFilter)
                    {
                        _textBoxOk();
                        return;
                    }

                    _items.Dispatch(r => r.ItemsSource = new RangeObservableCollection <TValue>(result));

                    if (!isCondition)
                    {
                        _textBoxOk();
                    }

                    OnFilterFinished(result);
                }
                catch {
                    _textBoxOk();
                }
                finally {
                    try {
                        if (finished != null)
                        {
                            finished();
                        }
                    }
                    catch {
                    }
                    IsFiltering = false;
                }
            }
        }
コード例 #17
0
 private static string GetValue <T>(DbAttribute isCard)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
		public void Set(DbAttribute mode, object value) {
			Set(mode.DisplayName, value);
		}
コード例 #19
0
ファイル: DbIOQuests.cs プロジェクト: zdurexz/RagnarokSDE
        public static void Loader <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            if (debug.FileType == FileType.Txt)
            {
                List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes);

                bool  rAthenaNewFormat = false;
                int[] oldColumns       =
                {
                    0, 1, 2, 3, 4, 5, 6, 7, 17
                };

                foreach (string[] elements in TextFileHelper.GetElementsByCommasQuotes(FtpHelper.ReadAllBytes(debug.FilePath)))
                {
                    try {
                        TKey id = (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFrom(elements[0]);

                        if (elements.Length == 18)
                        {
                            rAthenaNewFormat             = true;
                            db.Attached["rAthenaFormat"] = 18;
                        }

                        if (rAthenaNewFormat)
                        {
                            for (int index = 1; index < elements.Length; index++)
                            {
                                DbAttribute property = attributes[index];
                                db.Table.SetRaw(id, property, elements[index]);
                            }
                        }
                        else
                        {
                            for (int index = 1; index < oldColumns.Length; index++)
                            {
                                DbAttribute property = attributes[oldColumns[index]];
                                db.Table.SetRaw(id, property, elements[index]);
                            }
                        }
                    }
                    catch {
                        if (elements.Length <= 0)
                        {
                            if (!debug.ReportIdException("#"))
                            {
                                return;
                            }
                        }
                        else if (!debug.ReportIdException(elements[0]))
                        {
                            return;
                        }
                    }
                }
            }
            else if (debug.FileType == FileType.Conf)
            {
                var ele   = new LibconfigParser(debug.FilePath);
                var table = debug.AbsractDb.Table;

                foreach (var quest in ele.Output["copy_paste"] ?? ele.Output["quest_db"])
                {
                    try {
                        int  id      = Int32.Parse(quest["Id"]);
                        TKey questId = (TKey)(object)id;

                        table.SetRaw(questId, ServerQuestsAttributes.QuestTitle, "\"" + (quest["Name"] ?? "") + "\"");
                        table.SetRaw(questId, ServerQuestsAttributes.TimeLimit, (quest["TimeLimit"] ?? "0"));

                        var targets = quest["Targets"] as LibconfigList;

                        if (targets != null)
                        {
                            int count = 0;

                            foreach (var target in targets)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of targets has been reached (up to 3).", id, targets.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.TargetId1.Index + 2 * count], target["MobId"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Val1.Index + 2 * count], target["Count"] ?? "0");
                                count++;
                            }
                        }

                        var drops = quest["Drops"] as LibconfigList;

                        if (drops != null)
                        {
                            int count = 0;

                            foreach (var drop in drops)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of drops has been reached (up to 3).", id, drops.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.NameId1.Index + 3 * count], drop["ItemId"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Rate1.Index + 3 * count], drop["Rate"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.MobId1.Index + 3 * count], drop["MobId"] ?? "0");
                                count++;
                            }
                        }
                    }
                    catch {
                        if (quest["Id"] == null)
                        {
                            if (!debug.ReportIdException("#", quest.Line))
                            {
                                return;
                            }
                        }
                        else if (!debug.ReportIdException(quest["Id"], quest.Line))
                        {
                            return;
                        }
                    }
                }
            }
        }
コード例 #20
0
 private ClientCheevoAttributes(DbAttribute attribute)
     : base(attribute)
 {
     AttributeList.Add(this);
 }
コード例 #21
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetGender(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			int key = tuple.GetKey<int>();
			string val = tuple.GetValue<string>(attribute);

			if (key >= 1950 && key < 2000) {
				if (val == "0")
					return;
			}

			if (key == 2635) {
				if (val == "0")
					return;
			}

			if (val != "" && val != defaultValue && val != "-1") {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": ");
				builder.AppendLineUnix(val);
			}
		}
コード例 #22
0
 private ClientQuestsAttributes(DbAttribute attribute)
     : base(attribute)
 {
     AttributeList.Add(this);
 }
コード例 #23
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultEmptyAddHex(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			string val = "0x" + tuple.GetValue<string>(attribute);

			if (val != "" && val != defaultValue && val.Length > 2 && val.ToLower() != "0xffffffff") {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": ");
				builder.AppendLineUnix(val);
			}
		}
コード例 #24
0
        public void ApplyDicoCommand(GDbTabWrapper <TKey, TValue> tab, ListView lv, TValue tupleParent, DbAttribute attributeTable, TValue tuple, DbAttribute attribute, object value, bool reversable = true)
        {
            try {
                if (tab.ItemsEventsDisabled)
                {
                    return;
                }

                if (SdeAppConfiguration.EnableMultipleSetters && lv.SelectedItems.Count > 1)
                {
                    tab.Table.Commands.SetDico(tupleParent, lv.SelectedItems.Cast <TValue>().ToList(), attribute, value);
                }
                else
                {
                    if (tupleParent == null)
                    {
                        return;
                    }

                    var before       = tab.Table.Commands.CommandIndex;
                    var beforeGlobal = tab.ProjectDatabase.Commands.CommandIndex;
                    tab.Table.Commands.SetDico(tupleParent, attributeTable, tuple, attribute, value, reversable);
                    var after       = tab.Table.Commands.CommandIndex;
                    var afterGlobal = tab.ProjectDatabase.Commands.CommandIndex;

                    if (before > after && beforeGlobal == afterGlobal)
                    {
                        tab.ProjectDatabase.Commands.RemoveCommands(1);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
コード例 #25
0
        private static void _expandList(StringBuilder builder, ReadableTuple <int> tuple, string name, string level, string amount, DbAttribute attribute, string indent1, string indent2, string def, MetaTable <int> itemDb)
        {
            string value = tuple.GetValue <string>(attribute);

            if (value == def || value == "")
            {
                return;
            }

            string[] data = value.Split(':');
            int      k    = 1;

            if (data.Length == 1)
            {
                builder.Append(indent1);
                builder.Append(name);
                builder.Append(": ");
                builder.AppendLine(data[0]);
                return;
            }

            builder.Append(indent1);
            builder.Append(name);
            builder.AppendLine(":");

            if (attribute == ServerSkillAttributes.RequireItemCost)
            {
                for (int i = 0; i < data.Length; i += 2)
                {
                    builder.Append(level);
                    builder.Append(": ");
                    builder.AppendLine(DbIOUtils.Id2Name(itemDb, ServerItemAttributes.AegisName, data[i]));

                    if (i + 1 < data.Length)
                    {
                        builder.Append(indent2);
                        builder.Append(amount);
                        builder.Append(": ");
                        builder.AppendLine(data[i + 1]);
                    }
                    else
                    {
                        builder.Append(indent2);
                        builder.Append(amount);
                        builder.AppendLine(": 0");
                    }
                }

                return;
            }

            foreach (var field in data)
            {
                if (field == "")
                {
                    k++;
                    continue;
                }

                builder.Append(level);
                builder.Append(": ");
                builder.AppendLine(k.ToString(CultureInfo.InvariantCulture));
                k++;

                builder.Append(indent2);
                builder.Append(amount);
                builder.Append(": ");
                builder.AppendLine(field);
            }
        }
コード例 #26
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultLocation(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute)
        {
            string val = tuple.GetValue <string>(attribute);

            if (val != "" && val != "0")
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLine(val);
            }
        }
コード例 #27
0
ファイル: ItemParser.cs プロジェクト: secretdataz/RagnarokSDE
        private static void _trySetIfDefaultEmptyToHex(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = tuple.GetValue <string>(attribute);

            int ival;

            if (Int32.TryParse(val, out ival))
            {
                string sval = "0x" + ival.ToString("X").ToLower();

                if (val != defaultValue)
                {
                    builder.Append("\t");
                    builder.Append(attribute.AttributeName);
                    builder.Append(": ");
                    builder.AppendLineUnix(sval);
                }
            }
            else
            {
                Z.F();
            }
        }
コード例 #28
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultEmptyScript(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = tuple.GetValue <string>(attribute);

            if (val != "" && val != defaultValue)
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": <\"");
                builder.Append(ScriptFormat(val, 2, true));
                builder.AppendLine("\">");
            }
        }
コード例 #29
0
        public static void Loader <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            if (debug.FileType == FileType.Yaml)
            {
                var ele   = new YamlParser(debug.FilePath);
                var table = debug.AbsractDb.Table;

                if (ele.Output == null || ((ParserArray)ele.Output).Objects.Count == 0 || (ele.Output["copy_paste"] ?? ele.Output["Body"]) == null)
                {
                    return;
                }

                var mobDb  = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs);
                var itemDb = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

                foreach (var quest in ele.Output["copy_paste"] ?? ele.Output["Body"])
                {
                    try {
                        int  id      = Int32.Parse(quest["Id"]);
                        TKey questId = (TKey)(object)id;

                        table.SetRaw(questId, ServerQuestsAttributes.QuestTitle, "\"" + (quest["Title"] ?? "").Trim('\"') + "\"");
                        table.SetRaw(questId, ServerQuestsAttributes.TimeLimitNew, (quest["TimeLimit"] ?? ""));

                        var targets = quest["Targets"] as ParserList;

                        if (targets != null)
                        {
                            int count = 0;

                            foreach (var target in targets)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of targets has been reached (up to 3).", id, targets.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.TargetId1.Index + 2 * count], DbIOUtils.Name2Id(mobDb, ServerMobAttributes.AegisName, target["Mob"] ?? "", "mob_db", true));
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Val1.Index + 2 * count], target["Count"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Id1.Index + count], target["Id"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Race1.Index + count], target["Race"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Size1.Index + count], target["Size"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Element1.Index + count], target["Element"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.MinLevel1.Index + count], target["MinLevel"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.MaxLevel1.Index + count], target["MaxLevel"] ?? "0");
                                count++;
                            }
                        }

                        var drops = quest["Drops"] as ParserList;

                        if (drops != null)
                        {
                            int count = 0;

                            foreach (var drop in drops)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of drops has been reached (up to 3).", id, drops.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.NameId1.Index + 3 * count], DbIOUtils.Name2Id(itemDb, ServerItemAttributes.AegisName, drop["Item"] ?? "", "item_db", true));
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Rate1.Index + 3 * count], drop["Rate"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.MobId1.Index + 3 * count], DbIOUtils.Name2Id(mobDb, ServerMobAttributes.AegisName, drop["Mob"] ?? "", "mob_db", true));
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Count1.Index + count], drop["Count"] ?? "1");
                                count++;
                            }
                        }
                    }
                    catch {
                        if (quest["Id"] == null)
                        {
                            if (!debug.ReportIdException("#", quest.Line))
                            {
                                return;
                            }
                        }
                        else if (!debug.ReportIdException(quest["Id"], quest.Line))
                        {
                            return;
                        }
                    }
                }
            }
            else if (debug.FileType == FileType.Txt)
            {
                List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes);

                bool  rAthenaNewFormat = false;
                int[] oldColumns       =
                {
                    0, 1, 2, 3, 4, 5, 6, 7, 17
                };

                foreach (string[] elements in TextFileHelper.GetElementsByCommasQuotes(IOHelper.ReadAllBytes(debug.FilePath)))
                {
                    try {
                        TKey id = (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFrom(elements[0]);

                        if (elements.Length == 18)
                        {
                            rAthenaNewFormat             = true;
                            db.Attached["rAthenaFormat"] = 18;
                        }

                        if (rAthenaNewFormat)
                        {
                            for (int index = 1; index < elements.Length; index++)
                            {
                                DbAttribute property = attributes[index];
                                db.Table.SetRaw(id, property, elements[index]);
                            }
                        }
                        else
                        {
                            for (int index = 1; index < oldColumns.Length; index++)
                            {
                                DbAttribute property = attributes[oldColumns[index]];
                                db.Table.SetRaw(id, property, elements[index]);
                            }
                        }
                    }
                    catch {
                        if (elements.Length <= 0)
                        {
                            if (!debug.ReportIdException("#"))
                            {
                                return;
                            }
                        }
                        else if (!debug.ReportIdException(elements[0]))
                        {
                            return;
                        }
                    }
                }
            }
            else if (debug.FileType == FileType.Conf)
            {
                var ele   = new LibconfigParser(debug.FilePath);
                var table = debug.AbsractDb.Table;

                foreach (var quest in ele.Output["copy_paste"] ?? ele.Output["quest_db"])
                {
                    try {
                        int  id      = Int32.Parse(quest["Id"]);
                        TKey questId = (TKey)(object)id;

                        table.SetRaw(questId, ServerQuestsAttributes.QuestTitle, "\"" + (quest["Name"] ?? "") + "\"");
                        table.SetRaw(questId, ServerQuestsAttributes.TimeLimit, (quest["TimeLimit"] ?? "0"));

                        var targets = quest["Targets"] as ParserList;

                        if (targets != null)
                        {
                            int count = 0;

                            foreach (var target in targets)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of targets has been reached (up to 3).", id, targets.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.TargetId1.Index + 2 * count], target["MobId"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Val1.Index + 2 * count], target["Count"] ?? "0");
                                count++;
                            }
                        }

                        var drops = quest["Drops"] as ParserList;

                        if (drops != null)
                        {
                            int count = 0;

                            foreach (var drop in drops)
                            {
                                if (count >= 3)
                                {
                                    debug.ReportIdExceptionWithError("The maximum amount of drops has been reached (up to 3).", id, drops.Line);
                                    continue;
                                }

                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.NameId1.Index + 3 * count], drop["ItemId"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.Rate1.Index + 3 * count], drop["Rate"] ?? "0");
                                table.SetRaw(questId, ServerQuestsAttributes.AttributeList[ServerQuestsAttributes.MobId1.Index + 3 * count], drop["MobId"] ?? "0");
                                count++;
                            }
                        }
                    }
                    catch {
                        if (quest["Id"] == null)
                        {
                            if (!debug.ReportIdException("#", quest.Line))
                            {
                                return;
                            }
                        }
                        else if (!debug.ReportIdException(quest["Id"], quest.Line))
                        {
                            return;
                        }
                    }
                }
            }
        }
コード例 #30
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetGender(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            int    key = tuple.GetKey <int>();
            string val = tuple.GetValue <string>(attribute);

            if (key >= 1950 && key < 2000)
            {
                if (val == "0")
                {
                    return;
                }
            }

            if (key == 2635)
            {
                if (val == "0")
                {
                    return;
                }
            }

            if (val != "" && val != defaultValue && val != "-1")
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLine(val);
            }
        }
コード例 #31
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultEmptyBracket(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = tuple.GetValue <string>(attribute);

            if (val != "" && val != defaultValue)
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": [");
                builder.Append(val);
                builder.AppendLine("]");
            }
        }
コード例 #32
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultBoolean(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue)
        {
            if (tuple.GetRawValue(attribute.Index) as string == "")
            {
                return;
            }

            bool val = tuple.GetValue <bool>(attribute);

            if (val != defaultValue)
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLine(val.ToString().ToLower());
            }
        }
コード例 #33
0
		public bool Link(CheckBox box, DbAttribute attribute, bool? defaultValue = null) {
			return Link(box, attribute.DisplayName, defaultValue);
		}
コード例 #34
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfRefineable(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue)
        {
            int  type = tuple.GetValue <int>(ServerItemAttributes.Type);
            bool val  = tuple.GetValue <bool>(attribute);

            if (type != 4 && type != 5)
            {
                if (val)
                {
                    // This is not supposed to be allowed, but... we'll let it slide
                    DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "The refineable state on the item ID [" + tuple.GetKey <int>() + "] has been set to true but the item type is not an equipment. This is suspicious.", ErrorLevel.Warning);
                    builder.AppendLine("\t" + attribute.AttributeName + ": true");
                }
                return;
            }

            if (val != defaultValue)
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLine(val.ToString().ToLower());
            }
        }
コード例 #35
0
		public string Get(DbAttribute mode) {
			return Get(mode.DisplayName);
		}
コード例 #36
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultEmptyAddHexJobEx(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = "0x" + tuple.GetValue <string>(attribute);

            if (val != "" && val != defaultValue && val.Length > 2 && val.ToLower() != "0xffffffff")
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.AppendLine(": {");

                int value = FormatConverters.IntOrHexConverter(val);

                if (value == 0)
                {
                    builder.AppendLine("\t\tAll: false");
                    builder.AppendLine("\t}");
                    return;
                }

                if (value > 0)
                {
                    foreach (var job in DbIOItems.ItemDbJobs)
                    {
                        if ((value & job.Value) == job.Value)
                        {
                            builder.Append("\t\t");
                            builder.Append(job.Key);
                            builder.AppendLine(": true");
                        }
                    }
                }
                else
                {
                    builder.AppendLine("\t\tAll: true");

                    foreach (var job in DbIOItems.ItemDbJobs.Skip(1))
                    {
                        if ((value & ~job.Value) == ~job.Value)
                        {
                            builder.Append("\t\t");
                            builder.Append(job.Key);
                            builder.AppendLine(": false");
                        }
                    }
                }

                builder.AppendLine("\t}");
            }
        }
コード例 #37
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefault(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			if (tuple.GetValue<string>(attribute) != defaultValue) {
				builder.AppendLineUnix("\t" + attribute.AttributeName + ": " + tuple.GetValue<string>(attribute));
			}
		}
コード例 #38
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfDefaultEmptyAddHex(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = "0x" + tuple.GetValue <string>(attribute);

            if (val != "" && val != defaultValue && val.Length > 2 && val.ToLower() != "0xffffffff")
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLine(val);
            }
        }
コード例 #39
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultEmptyScript(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			string val = tuple.GetValue<string>(attribute);

			if (val != "" && val != defaultValue) {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": <\"");
				builder.Append(Format(val, 2, true));
				builder.AppendLineUnix("\">");
			}
		}
コード例 #40
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfNotDefault(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue, bool useConstants, string constGroup)
        {
            if (!useConstants)
            {
                TrySetIfNotDefault(tuple, builder, attribute, defaultValue);
                return;
            }

            string val = tuple.GetValue <string>(attribute);

            if (val != defaultValue)
            {
                builder.AppendLine("\t" + attribute.AttributeName + ": \"" + SdeEditor.Instance.ProjectDatabase.IntToConstant(Int32.Parse(val), constGroup) + "\"");
            }
        }
コード例 #41
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultEmptyBracket(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			string val = tuple.GetValue<string>(attribute);

			if (val != "" && val != defaultValue) {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": [");
				builder.Append(val);
				builder.AppendLineUnix("]");
			}
		}
コード例 #42
0
ファイル: DbIOFormatting.cs プロジェクト: zdurexz/RagnarokSDE
        public static void TrySetIfNotDefault(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = tuple.GetValue <string>(attribute);

            if (val != defaultValue)
            {
                builder.AppendLine("\t" + attribute.AttributeName + ": " + val);
            }
        }
コード例 #43
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfRefineable(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue) {
			int type = tuple.GetValue<int>(ServerItemAttributes.Type);
			bool val = tuple.GetValue<bool>(attribute);

			if (type != 4 && type != 5) {
				if (val) {
					// This is not supposed to be allowed, but... we'll let it slide
					DbLoaderErrorHandler.Handle("The refineable status on the item ID [" + tuple.GetKey<int>() + "] has been set to true but the item type is not an equipment. This is suspicious.", ErrorLevel.Warning);
					builder.AppendLineUnix("\t" + attribute.AttributeName + ": true");
				}
				return;
			}

			if (val != defaultValue) {
				builder.Append("\t");
				builder.Append(attribute.AttributeName);
				builder.Append(": ");
				builder.AppendLineUnix(val.ToString().ToLower());
			}
		}
コード例 #44
0
ファイル: DbMaker.cs プロジェクト: Tokeiburu/RagnarokSDE
		public bool Init(DbHolder holder) {
			try {
				if (!File.Exists(_file)) return false;

				string dbRawName = Path.GetFileNameWithoutExtension(_file);
				string dbName = _toDbName(dbRawName.Replace("_db", ""));
				string[] lines = File.ReadAllLines(_file);
				string[] itemsRaw = null;
				bool waitOne = false;

				foreach (string line in lines) {
					string t = line;

					string[] raw = t.Replace("[,", ",[").Replace("{,", ",{").Split(',');

					if (waitOne && raw.Length <= 1) break;

					if (waitOne) {
						raw[0] = raw[0].TrimStart('/', ' ', '\t');
						itemsRaw = itemsRaw.Concat(raw).ToArray();
					}
					else {
						itemsRaw = raw;
					}

					if (itemsRaw.Length > 1) {
						int end = itemsRaw.Length - 1;
						itemsRaw[end] = itemsRaw[end].Contains("//") ? itemsRaw[end].Substring(0, itemsRaw[end].IndexOf("//", StringComparison.Ordinal)) : itemsRaw[end];
						waitOne = true;
					}
				}

				if (itemsRaw == null || itemsRaw.Length <= 1) return false;

				Dictionary<int, string> comments = new Dictionary<int, string>();

				foreach (string line in lines) {
					if (!line.StartsWith("//")) break;

					string bufLine = line.Trim('/', ' ');

					if (bufLine.Length > 2 && bufLine[2] == '.') {
						int ival;

						if (Int32.TryParse(bufLine.Substring(0, 2), out ival)) {
							string t = bufLine.Substring(3).Trim(' ', '\t');

							int index = t.LastIndexOf("  ", StringComparison.Ordinal);

							if (index > -1) {
								t = t.Substring(index);
							}
							else {
								index = t.LastIndexOf("\t\t", StringComparison.Ordinal);

								if (index > -1) {
									t = t.Substring(index);
								}
							}

							comments[ival] = t.Trim(' ', '\t');
						}
					}
				}

				List<string> items = itemsRaw.ToList();

				items[0] = items[0].TrimStart('/', ' ');
				items = items.ToList().Select(p => p.Trim(' ')).ToList();
				HashSet<int> variable = new HashSet<int>();

				if (items.Any(p => p == "...")) {
					// Find the longest line

					if (_hasLogic(items, variable)) { }
					else {
						int itemIndex = items.IndexOf("...");
						List<int> count = lines.Select(line => line.Split(',').Length).ToList();

						int missingArguments = count.Max(p => p) - items.Count;

						if (missingArguments == 0) {
							items[itemIndex] = "Unknown";
						}
						else if (missingArguments < 0) {
							items.RemoveAt(itemIndex);
						}
						else {
							items.RemoveAt(itemIndex);

							for (int i = 0; i < missingArguments; i++) {
								items.Insert(itemIndex, "Variable");
								variable.Add(itemIndex + i);
							}
						}
					}
				}

				if (items.Any(p => p.Contains('[')) || items.Any(p => p.Contains('{'))) {
					bool begin = false;

					for (int i = 0; i < items.Count; i++) {
						if (items[i].StartsWith("[") || items[i].StartsWith("{")) {
							if (items[i] != "{}")
								begin = true;
						}

						if (begin) {
							variable.Add(i);
						}

						if (items[i].EndsWith("]") || items[i].EndsWith("}")) {
							begin = false;
						}
					}
				}

				items = items.Select(p => p.Trim('[', ']', '{', '}')).ToList();

				AttributeList list = new AttributeList();

				IntLineStream reader = new IntLineStream(_file);
				Type dbType = typeof (int);

				bool? duplicates = reader.HasDuplicateIds();

				if (duplicates == null || duplicates == true) {
					dbType = typeof (string);
				}

				bool first = true;
				DbAttribute bindingAttribute = null;

				for (int i = 0; i < items.Count; i++) {
					string value = items[i];
					string desc = null;
					string toDisplay = _toDisplay(value);
					DbAttribute att;

					if (comments.ContainsKey(i + 1))
						desc = comments[i + 1];

					if (i == 0 && first) {
						if (duplicates == null) {
							att = new PrimaryAttribute(value, dbType, 0, toDisplay);
						}
						else if (duplicates == true) {
							att = new PrimaryAttribute("RealId", dbType, "");
							first = false;
							i--;
						}
						else {
							att = new PrimaryAttribute(value, dbType, 0, toDisplay);
						}
					}
					else {
						string toLower = value.ToLower();
						CustomAttribute custom = new CustomAttribute(value, typeof(string), "", toDisplay, desc);
						att = custom;

						if (toLower.Contains("skillid")) {
							att.AttachedObject = ServerDbs.Skills;
							custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>));
							if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
						}

						if (toLower.Contains("mobid")) {
							att.AttachedObject = ServerDbs.Mobs;
							custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>));
							if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
						}

						if (toLower.Contains("itemid")) {
							att.AttachedObject = ServerDbs.Items;
							custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty<int>) : typeof(SelectTupleProperty<string>));
							if (i == 1) bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
						}

						if (variable.Contains(i))
							att.IsSkippable = true;
					}

					list.Add(att);
				}

				if (bindingAttribute != null)
					list.Add(bindingAttribute);
				else {
					string toLower = items[0].ToLower();

					if (toLower.Contains("skillid")) {
						bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
					}

					if (toLower.Contains("mobid")) {
						bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
					}

					if (toLower.Contains("itemid")) {
						bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1) { IsDisplayAttribute = true, Visibility = VisibleState.Hidden };
					}

					if (bindingAttribute != null)
						list.Add(bindingAttribute);
				}


				if (dbType == typeof(int)) {
					_adb = new DummyDb<int>();

					_adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDb;
					_adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromItemDb;
					_adb.To<int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDb;
				}
				else {
					_adb = new DummyDb<string>();

					var db = _adb.To<string>();

					if (duplicates == true) {
						db.LayoutIndexes = new int[] {
							1, list.Attributes.Count
						};

						db.DbLoader = DbLoaderMethods.DbUniqueLoader;
						db.DbWriter = DbWriterMethods.DbUniqueWriter;

						db.TabGenerator.OnInitSettings += delegate(GDbTabWrapper<string, ReadableTuple<string>> tab, GTabSettings<string, ReadableTuple<string>> settings, BaseDb gdb) {
							settings.CanChangeId = false;
							settings.CustomAddItemMethod = delegate {
								try {
									string id = Methods.RandomString(32);

									ReadableTuple<string> item = new ReadableTuple<string>(id, settings.AttributeList);
									item.Added = true;

									db.Table.Commands.StoreAndExecute(new AddTuple<string, ReadableTuple<string>>(id, item));
									tab._listView.ScrollToCenterOfView(item);
								}
								catch (KeyInvalidException) {
								}
								catch (Exception err) {
									ErrorHandler.HandleException(err);
								}
							};
						};
						db.TabGenerator.StartIndexInCustomMethods = 1;
						db.TabGenerator.OnInitSettings += delegate(GDbTabWrapper<string, ReadableTuple<string>> tab, GTabSettings<string, ReadableTuple<string>> settings, BaseDb gdb) {
							settings.AttributeList = gdb.AttributeList;
							settings.AttId = gdb.AttributeList.Attributes[1];
							settings.AttDisplay = gdb.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? gdb.AttributeList.Attributes[2];
							settings.AttIdWidth = 60;
						};
						db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDbString;
						db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDbString;
					}
					else if (duplicates == null) {
						db.UnsafeContext = true;
						db.DbWriter = DbWriterMethods.DbStringCommaWriter;
					}
				}

				ServerDbs sdb = ServerDbs.Instantiate(dbRawName, dbName, FileType.Txt);

				if (bindingAttribute != null)
					bindingAttribute.AttachedObject = _adb;

				_adb.IsCustom = true;
				_adb.DbSource = sdb;
				_adb.AttributeList = list;

				return true;
			}
			catch { }
			return false;
		}
コード例 #45
0
ファイル: ItemParser.cs プロジェクト: Tokeiburu/RagnarokSDE
		private static void _trySetIfDefaultEmptyToHex(ReadableTuple<int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue) {
			string val = tuple.GetValue<string>(attribute);

			int ival;

			if (Int32.TryParse(val, out ival)) {
				string sval = "0x" + ival.ToString("X").ToLower();

				if (val != defaultValue) {
					builder.Append("\t");
					builder.Append(attribute.AttributeName);
					builder.Append(": ");
					builder.AppendLineUnix(sval);
				}
			}
			else {
				Z.F();
			}
		}
コード例 #46
0
		private ClientResourceAttributes(DbAttribute attribute)
			: base(attribute) {
			AttributeList.Add(this);
		}
コード例 #47
0
		private Experssion GetExper(DbElement gEle, DbAttribute attr)
		{
			Dictionary<string, Experssion> map = null;
			if (!experMap.TryGetValue(attr, out map))
			{
				map = new Dictionary<string, Experssion>();
				experMap.Add(attr, map);
			}

			Experssion exper = null;
			if (!map.TryGetValue(gEle.GetAsString(DbAttributeInstance.NAME), out exper))
			{
				exper = new Experssion(gEle.GetAsString(attr));
				map.Add(gEle.GetAsString(DbAttributeInstance.NAME), exper);
			}

			return exper;
		}
コード例 #48
0
ファイル: ItemParser.cs プロジェクト: secretdataz/RagnarokSDE
 private static void _trySet(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute)
 {
     builder.Append("\t");
     builder.Append(attribute.AttributeName);
     builder.Append(": ");
     builder.AppendLineUnix(tuple.GetValue <string>(attribute));
 }
コード例 #49
0
ファイル: DbMaker.cs プロジェクト: Tokeiburu/RagnarokSDE
			public CustomAttribute(DbAttribute attribute) : base(attribute) {
			}
コード例 #50
0
        public static void ExpandFlagYaml <T>(StringBuilder builder, ReadableTuple <int> tuple, string name, DbAttribute attribute, string indent1, string indent2, Func <bool> isExtra = null, Action extra = null)
        {
            long value = FormatConverters.LongOrHexConverter(tuple.GetValue <string>(attribute));

            if (value != 0 || (isExtra != null && isExtra()))
            {
                if (name != "")
                {
                    builder.Append(indent1);
                    builder.Append(name);
                    builder.AppendLine(": {");
                }

                var flagsData = FlagsManager.GetFlag <T>();

                if (flagsData != null)
                {
                    foreach (var v in flagsData.Values)
                    {
                        long vF = v.Value;

                        if ((v.DataFlag & FlagDataProperty.Hide) == FlagDataProperty.Hide)
                        {
                            continue;
                        }

                        if ((vF & value) == vF)
                        {
                            builder.Append(indent2);
                            builder.Append(v.Name);
                            builder.AppendLine(": true");
                        }
                    }
                }
                else
                {
                    foreach (var v in Enum.GetValues(typeof(T)).Cast <T>())
                    {
                        int vF = (int)(object)v;

                        if ((vF & value) == vF)
                        {
                            builder.Append(indent2);
                            builder.Append(Constants.ToString(v));
                            builder.AppendLine(": true");
                        }
                    }
                }

                if (extra != null)
                {
                    extra();
                }

                builder.Append(indent1);
                builder.AppendLine("}");
            }
        }
コード例 #51
0
 private static void PostSetRefAttSubscriber(DbElement ele, DbAttribute att, DbElement oldref)
 {
     Console.WriteLine("PostRefAtt");
 }
コード例 #52
0
        public static object Name2IdBuffered(IEnumerable <ReadableTuple <int> > table, DbAttribute attribute, string name, string table_sourc, bool silent)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(0);
            }

            int res;

            if (Int32.TryParse(name, out res))
            {
                return(res);
            }

            if (!_bufferedDicos.ContainsKey(table_sourc))
            {
                _bufferedDicos[table_sourc] = new Dictionary <string, int>();
                var dico = _bufferedDicos[table_sourc];

                foreach (var entry2 in table)
                {
                    dico[entry2.GetStringValue(attribute.Index)] = entry2.Key;
                }
            }

            var metaDico = _bufferedDicos[table_sourc];
            int ival;

            if (metaDico.TryGetValue(name, out ival))
            {
                return(ival);
            }

            if (silent)
            {
                return(name);
            }

            throw new Exception("Unable to convert the name '" + name + "' to an ID. This means the name is not defined in your " + table_sourc + " file and SDE requires it.");
        }
コード例 #53
0
        private static void _saveFile(SdeDatabase gdb, string filename, string output, DbAttribute attribute, RequiredCondition <ReadableTuple <int> > condition = null, bool allowReturns = true)
        {
            if (output == null && gdb.MetaGrf.GetData(filename) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, filename, null, "Table not saved (" + attribute.GetQueryName() + ")."));
                return;
            }

            if (output == null)
            {
                BackupEngine.Instance.BackupClient(filename, gdb.MetaGrf);
            }

            string   tmpFilename = Path.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(filename));
            Encoding encoder     = EncodingService.DisplayEncoding;

            byte[] tmpBuffer;
            byte[] lineFeedByte       = encoder.GetBytes(SdeStrings.LineFeed);
            byte[] doubleLineFeedByte = encoder.GetBytes(SdeStrings.LineFeed + SdeStrings.LineFeed);

            using (MemoryStream memStream = new MemoryStream()) {
                IEnumerable <ReadableTuple <int> > items = gdb.GetDb <int>(ServerDbs.CItems).Table.GetSortedItems();

                int  previousId = -1;
                bool firstItem  = true;

                foreach (ReadableTuple <int> item in items)
                {
                    if (condition == null || condition(item))
                    {
                        string itemProperty = attribute != null?item.GetRawValue(attribute.Index) as string : null;

                        if (itemProperty != null || attribute == null)
                        {
                            if (attribute == ClientItemAttributes.IdentifiedDisplayName || attribute == ClientItemAttributes.UnidentifiedDisplayName)
                            {
                                itemProperty = itemProperty.Replace(" ", "_");
                            }

                            if (!firstItem)
                            {
                                if (allowReturns)
                                {
                                    if (previousId == (item.GetValue <int>(ClientItemAttributes.Id) - 1))
                                    {
                                        memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                    }
                                    else
                                    {
                                        memStream.Write(doubleLineFeedByte, 0, doubleLineFeedByte.Length);
                                    }
                                }
                                else
                                {
                                    memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                }
                            }

                            if (attribute == null)
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#");
                            }
                            else
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#" + itemProperty + "#");
                            }

                            memStream.Write(tmpBuffer, 0, tmpBuffer.Length);

                            previousId = item.GetValue <int>(ClientItemAttributes.Id);
                            firstItem  = false;
                        }
                    }
                }

                memStream.Write(lineFeedByte, 0, lineFeedByte.Length);

                tmpBuffer = new byte[memStream.Length];
                Buffer.BlockCopy(memStream.GetBuffer(), 0, tmpBuffer, 0, tmpBuffer.Length);

                File.WriteAllBytes(tmpFilename, tmpBuffer);
            }

            if (output == null)
            {
                var data    = gdb.MetaGrf.GetData(filename);
                var toWrite = File.ReadAllBytes(tmpFilename);

                if (data != null && Methods.ByteArrayCompare(data, toWrite))
                {
                    return;
                }

                gdb.MetaGrf.SetData(filename, toWrite);
            }
            else
            {
                string copyPath = Path.Combine(output, Path.GetFileName(filename));

                try {
                    File.Delete(copyPath);
                    File.Copy(tmpFilename, copyPath);
                    File.Delete(tmpFilename);
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, gdb.MetaGrf.FindTkPath(filename), null, "Saving client table (" + (attribute == null ? "" : attribute.GetQueryName()) + ")."));
        }
コード例 #54
0
ファイル: ItemParser.cs プロジェクト: secretdataz/RagnarokSDE
        private static void _trySetIfDefaultEmptyUpper(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute)
        {
            string val = tuple.GetValue <string>(attribute);

            if (val != "" && val != "7" && val != "63")
            {
                builder.Append("\t");
                builder.Append(attribute.AttributeName);
                builder.Append(": ");
                builder.AppendLineUnix(val);
            }
        }