public static void DbItemsBuyingStore <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    bool item1 = tuple.GetValue <bool>(ServerItemAttributes.BuyingStore);

                    if (!item1)
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = key.ToString(CultureInfo.InvariantCulture) + "  // " + tuple.GetValue <string>(ServerItemAttributes.AegisName);
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #2
0
        public static void DbItemsStack <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key      = tuple.Key;
                        var elements = tuple.Value;
                        var tuple1   = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            string val1 = tuple1.GetValue <string>(ServerItemAttributes.Stack);
                            string val2 = elements[1];

                            if (val1 != val2)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.Stack);

                    if (item1 == "")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = String.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1 }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #3
0
        public static void DbSkillsCastCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int length)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    List <string> items = tuple.GetRawElements().Skip(from).Take(length).Select(p => p.ToString()).ToList();

                    if (items.All(p => p == "0"))
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture) }.Concat(items).ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbItemsStack <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.Stack);

                    if (item1 == "")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1 }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbItemsNouse <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(db.UsePreviousOutput ? debug.FilePath : debug.OldPath);
                lines.Remove(db);
                string line;
                NoUse  nouse = new NoUse();

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(ServerItemAttributes.NoUse);
                    nouse.Override = ParserHelper.GetVal(item1, "override", "100");
                    nouse.Sitting  = ParserHelper.GetVal(item1, "sitting", "false");

                    if (nouse.Override == "100" && nouse.Sitting == "false")
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), nouse.Sitting == "true" ? "1" : "0", nouse.Override }.ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #6
0
        public static void DbItemsBuyingStore <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key    = tuple.Key;
                        var tuple1 = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            bool val1 = tuple1.GetValue <bool>(ServerItemAttributes.BuyingStore);

                            if (val1 != true)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    bool item1 = tuple.GetValue <bool>(ServerItemAttributes.BuyingStore);

                    if (!item1)
                    {
                        lines.Delete(key);
                        continue;
                    }

                    line = key.ToString(CultureInfo.InvariantCulture) + "  // " + tuple.GetValue <string>(ServerItemAttributes.AegisName);
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbIntCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int to)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                for (int i = from; i < to; i++)
                {
                    DbAttribute att = db.AttributeList.Attributes[i];

                    if (att.Visibility == VisibleState.Hidden)
                    {
                        to = i;
                        break;
                    }
                }

                List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes.Skip(from).Take(to));
                attributes.Reverse();

                List <DbAttribute> attributesToRemove =
                    (from attribute in attributes where db.Attached[attribute.DisplayName] != null
                     let isLoaded = (bool)db.Attached[attribute.DisplayName]
                                    where !isLoaded
                                    select attribute).ToList();

                IEnumerable <ReadableTuple <TKey> > list;

                if (db.Attached["EntireRewrite"] != null && (bool)db.Attached["EntireRewrite"])
                {
                    list = db.Table.FastItems.Where(p => !p.Deleted).OrderBy(p => p.GetKey <TKey>());
                }
                else
                {
                    list = db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>());
                }

                foreach (ReadableTuple <TKey> tuple in list)
                {
                    int           key         = tuple.GetKey <int>();
                    List <object> rawElements = tuple.GetRawElements().Skip(from).Take(to).ToList();

                    foreach (var attribute in attributesToRemove)
                    {
                        rawElements.RemoveAt(attribute.Index - from);
                    }

                    line = string.Join(",", rawElements.Select(p => (p ?? "").ToString()).ToArray());
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #8
0
        public static void Writer <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            if (debug.FileType == FileType.Conf)
            {
                try {
                    var lines = new LibconfigParser(debug.OldPath, LibconfigMode.Write);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int           key     = tuple.GetKey <int>();
                        StringBuilder builder = new StringBuilder();
                        WriteEntry(builder, tuple);
                        line = builder.ToString();
                        lines.Write(key.ToString(CultureInfo.InvariantCulture), line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
            else
            {
                int format = db.GetAttacked <int>("rAthenaFormat");

                try {
                    IntLineStream lines = new IntLineStream(debug.OldPath);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int key = tuple.GetKey <int>();

                        if (format == 18)
                        {
                            line = string.Join(",", tuple.GetRawElements().Select(p => (p ?? "").ToString()).ToArray());
                        }
                        else
                        {
                            line = string.Join(",", tuple.GetRawElements().Take(ServerQuestsAttributes.MobId1.Index).Concat(new object[] { tuple.GetRawValue(ServerQuestsAttributes.QuestTitle.Index) }).Select(p => (p ?? "").ToString()).ToArray());
                        }

                        lines.Write(key, line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
        }
Example #9
0
        public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db, int groupId)
        {
            bool isHercules = (db.Attached[ServerMobBossAttributes.MobGroup.DisplayName] != null && !(bool)db.Attached[ServerMobBossAttributes.MobGroup.DisplayName]);

            try {
                IntLineStream lines     = new IntLineStream(debug.OldPath, isHercules ? 0 : 1);
                bool          isChanged = lines.Remove2(db, groupId);
                string        line;

                var tupleParent = db.Table.TryGetTuple(groupId);

                if (tupleParent == null)
                {
                    // File content was deleted
                    lines.ClearAfterComments();
                    lines.WriteFile(debug.FilePath);
                    return;
                }

                var dico   = (Dictionary <int, ReadableTuple <int> >)tupleParent.GetRawValue(ServerMobGroupAttributes.Table.Index);
                var values = dico.Values.Where(p => !p.Normal).OrderBy(p => p.Key).ToList();

                if (values.Count == 0 && !isChanged)
                {
                    return;
                }

                foreach (ReadableTuple <int> tuple in values)
                {
                    int key         = tuple.Key;
                    var rawElements = tuple.GetRawElements().Select(p => (p ?? "").ToString()).ToArray();

                    if (isHercules)
                    {
                        line = string.Join(",", new string[] { rawElements[0], rawElements[1], rawElements[2] });
                    }
                    else
                    {
                        line = string.Join(",", new string[] { _groupIdToConst(groupId), rawElements[0], rawElements[1], rawElements[2] });
                    }

                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
        public static void DbSkillsCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int length)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                ServerType serverType;

                if (db.Attached["DbCommaLoaderSkill.IsRAthena"] == null)
                {
                    serverType = ServerType.Hercules;
                }
                else
                {
                    serverType = (bool)db.Attached["DbCommaLoaderSkill.IsRAthena"] ? ServerType.RAthena : ServerType.Hercules;
                }

                if (serverType == ServerType.RAthena)
                {
                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int key = tuple.GetKey <int>();

                        List <string> items = tuple.GetRawElements().Skip(from).Take(length).Select(p => p.ToString()).ToList();
                        lines.Write(key, string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture) }.Concat(items).ToArray()));
                    }
                }
                else
                {
                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int key = tuple.GetKey <int>();

                        var items = tuple.GetRawElements().Skip(0).Take(length + 1).Select(p => p.ToString()).ToList();
                        items.RemoveAt(ServerSkillAttributes.Inf3.Index);

                        lines.Write(key, string.Join(",", items.ToArray()));
                    }
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #11
0
        public static void DbSkillsNoCastCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int length)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string item1 = tuple.GetValue <string>(from);
                    string item2 = tuple.GetValue <string>(from + 1);

                    if (item1 != "0" && item2 == "0")
                    {
                        line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1 });
                    }
                    else if (item1 == "0" && item2 == "0")
                    {
                        lines.Delete(key);
                        continue;
                    }
                    else
                    {
                        line = string.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), item1, item2 });
                    }

                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #12
0
		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;
		}
Example #13
0
        public static void DbItemsCommaRange <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, int from, int length, string defaultValue, Func <ReadableTuple <TKey>, List <string>, string, string> append)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key      = tuple.Key;
                        var elements = tuple.Value;
                        var tuple1   = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            string val1 = tuple1.GetValue <string>(@from);
                            string val2 = elements[1];

                            if (val1 != val2)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    List <string> items = tuple.GetRawElements().Skip(@from).Take(length).Select(p => p.ToString()).ToList();

                    if (items.All(p => p == defaultValue))
                    {
                        lines.Delete(key);
                        continue;
                    }

                    if (append != null)
                    {
                        line = append(tuple, items, String.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture) }.Concat(items).ToArray()));
                    }
                    else
                    {
                        line = String.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture) }.Concat(items).ToArray());
                    }
                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #14
0
        public static void DbItemsTrade <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                IntLineStream lines = new IntLineStream(debug.OldPath);
                lines.Remove(db);
                string line;

                TkDictionary <TKey, string[]> phantom = _getPhantomTable(debug);

                if (phantom != null)
                {
                    var itemDb = debug.AbsractDb.GetDb <TKey>(ServerDbs.Items).Table;

                    // Check if the phantom values differ from the Items1
                    foreach (var tuple in phantom)
                    {
                        if (debug.AbsractDb.Table.ContainsKey(tuple.Key))
                        {
                            continue;
                        }

                        var key      = tuple.Key;
                        var elements = tuple.Value;
                        var tuple1   = itemDb.TryGetTuple(key);

                        if (tuple1 != null)
                        {
                            int val1 = tuple1.GetIntNoThrow(ServerItemAttributes.TradeFlag);
                            int val2 = FormatConverters.IntOrHexConverter(elements[1]);

                            int val3 = tuple1.GetIntNoThrow(ServerItemAttributes.TradeOverride);
                            int val4 = FormatConverters.IntOrHexConverter(elements[2]);

                            // There is no flag set
                            if (val1 != val2 || val3 != val4)
                            {
                                lines.Delete(tuple1.GetKey <int>());
                            }
                        }
                    }
                }

                foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                {
                    int key = tuple.GetKey <int>();

                    string overrideValue = tuple.GetValue <string>(ServerItemAttributes.TradeOverride);
                    string flagValue     = tuple.GetValue <string>(ServerItemAttributes.TradeFlag);

                    if (flagValue == "0")
                    {
                        if (overrideValue == "100" || SdeAppConfiguration.DbTradeIgnoreOverride)
                        {
                            lines.Delete(key);
                            continue;
                        }
                    }

                    line = String.Join(",", new string[] { key.ToString(CultureInfo.InvariantCulture), flagValue, overrideValue }.ToArray());

                    if (SdeAppConfiguration.AddCommentForItemTrade)
                    {
                        line += "\t// " + tuple.GetValue <string>(ServerItemAttributes.AegisName);
                    }

                    lines.Write(key, line);
                }

                lines.WriteFile(debug.FilePath);
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
Example #15
0
        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);
        }
Example #16
0
        public static void Writer <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            if (debug.FileType == FileType.Yaml)
            {
                var itemDb = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);
                var mobDb  = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs);

                try {
                    var lines = new YamlParser(debug.OldPath, ParserMode.Write, "Id");

                    if (lines.Output == null)
                    {
                        return;
                    }

                    lines.Remove(db, v => DbIOUtils.Id2Name(mobDb, ServerMobAttributes.AegisName, v.ToString()));

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <int>()))
                    {
                        string key = tuple.Key.ToString();

                        StringBuilder builder = new StringBuilder();
                        WriteEntryYaml(builder, tuple, itemDb, mobDb);
                        lines.Write(key, builder.ToString().Trim('\r', '\n'));
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
            else if (debug.FileType == FileType.Conf)
            {
                try {
                    var lines = new LibconfigParser(debug.OldPath, ParserMode.Write);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int           key     = tuple.GetKey <int>();
                        StringBuilder builder = new StringBuilder();
                        WriteEntry(builder, tuple);
                        line = builder.ToString();
                        lines.Write(key.ToString(CultureInfo.InvariantCulture), line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
            else
            {
                int format = db.GetAttacked <int>("rAthenaFormat");

                try {
                    IntLineStream lines = new IntLineStream(debug.OldPath);
                    lines.Remove(db);
                    string line;

                    foreach (ReadableTuple <TKey> tuple in db.Table.FastItems.Where(p => !p.Normal).OrderBy(p => p.GetKey <TKey>()))
                    {
                        int key = tuple.GetKey <int>();

                        if (format == 18)
                        {
                            line = string.Join(",", tuple.GetRawElements().Take(18).Select(p => (p ?? "").ToString()).ToArray());
                        }
                        else
                        {
                            line = string.Join(",", tuple.GetRawElements().Take(ServerQuestsAttributes.MobId1.Index).Concat(new object[] { tuple.GetRawValue(ServerQuestsAttributes.QuestTitle.Index) }).Select(p => (p ?? "").ToString()).ToArray());
                        }

                        lines.Write(key, line);
                    }

                    lines.WriteFile(debug.FilePath);
                }
                catch (Exception err) {
                    debug.ReportException(err);
                }
            }
        }