Exemple #1
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);
            }
        }
        private string _generateDescription(TkDictionary <string, string> para)
        {
            string description = "";

            description += _trimReturns(para[ParameterHolderKeys.Description]);
            description += "\r\n";

            if (para.Count < 3)
            {
                if (!description.EndsWith("^ffffff_^000000\r\n"))
                {
                    description += "^ffffff_^000000\r\n";
                }
            }

            _addDescFor(ref description, para[KnownParameterHolderKeys[0]], 1);
            _addDescFor(ref description, para[KnownParameterHolderKeys[1]], 2);
            _addDescFor(ref description, para[KnownParameterHolderKeys[2]], 3);
            _addDescFor(ref description, para[KnownParameterHolderKeys[3]], 4);
            _addDescFor(ref description, para[KnownParameterHolderKeys[4]], 5);
            _addDescFor(ref description, para[KnownParameterHolderKeys[10]], 11);
            _addDescFor(ref description, para[KnownParameterHolderKeys[5]], 6);
            _addDescFor(ref description, para[KnownParameterHolderKeys[11]], 12);

            var property = para[ParameterHolderKeys.Property];

            if (!String.IsNullOrEmpty(property))
            {
                string[] properties = property.Split(',').Select(p => p.Trim(' ')).ToArray();

                properties = properties.Where(p => p != "").ToArray();

                if (properties.Length > 0)
                {
                    description += KnownParameterHolderKeys[6].Display + " :";

                    foreach (string prop in properties)
                    {
                        try {
                            description += ProjectConfiguration.AutocompleteProperties[Properties.ToList().IndexOf(prop)];
                        }
                        catch {
                            description += "^000000";
                        }
                        description += " " + prop + "^000000, ";
                    }

                    description  = description.Remove(description.Length - 2, 2);
                    description += "\r\n";
                }
            }

            _addDescFor(ref description, para[KnownParameterHolderKeys[7]], 8);
            _addDescFor(ref description, para[KnownParameterHolderKeys[8]], 9);
            _addDescFor(ref description, para[KnownParameterHolderKeys[9]], 10);

            return(description.Trim('\r', '\n'));
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        private static void _loadFallbackValues(Dictionary <int, string> fallbackSprites, List <ReadableTuple <int> > headgears, IDictionary <string, string> accIdT, IDictionary <string, string> accNameT, IDictionary <string, int> resourceToIds, Dictionary <int, string> redirectionTable)
        {
            TkDictionary <int, ReadableTuple <int> > buffered = new TkDictionary <int, ReadableTuple <int> >();
            var rRedirectionTable = new HashSet <string>();

            foreach (var headgear in headgears)
            {
                if (!buffered.ContainsKey(headgear.Key))
                {
                    buffered[headgear.Key] = headgear;
                }
            }

            foreach (var pair in redirectionTable)
            {
                rRedirectionTable.Add(pair.Value);
            }

            foreach (var keyPair in fallbackSprites)
            {
                if (rRedirectionTable.Contains(keyPair.Value))
                {
                    continue;
                }
                if (keyPair.Key <= 0)
                {
                    continue;                                   // throw new Exception("View ID cannot be equal or below 0.");
                }
                var    sTuple = buffered[keyPair.Key];          // headgears.FirstOrDefault(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber) == keyPair.Key);
                string accessoryName;

                if (sTuple != null)
                {
                    accessoryName = GetAccAegisNameFromTuple(sTuple);
                }
                else
                {
                    // No item associated with this view ID
                    accessoryName = String.Format("UNREGISTERED_{0:0000}", keyPair.Key);
                }

                // Bogus entry - entry by number
                if (keyPair.Key.ToString(CultureInfo.InvariantCulture) == keyPair.Value)
                {
                    continue;
                }

                accIdT["ACCESSORY_" + accessoryName] = keyPair.Key.ToString(CultureInfo.InvariantCulture);
                accNameT["[ACCESSORY_IDs.ACCESSORY_" + accessoryName + "]"] = "\"_" + keyPair.Value + "\"";
                resourceToIds[keyPair.Value] = keyPair.Key;
            }
        }
Exemple #5
0
        public static void DbLoaderCommaRange <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(FtpHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                    if (!addAutomatically && !table.ContainsKey(itemId))
                    {
                        TkDictionary <T, string[]> phantomTable;

                        if (!debug.AbsractDb.Attached.ContainsKey("Phantom." + debug.DbSource.Filename))
                        {
                            phantomTable = new TkDictionary <T, string[]>();
                            debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename] = phantomTable;
                        }
                        else
                        {
                            phantomTable = (TkDictionary <T, string[]>)debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename];
                        }

                        phantomTable[itemId] = elements;
                        continue;
                    }

                    int max = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];
                        table.SetRaw(itemId, property, elements[index]);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
Exemple #6
0
        public static void DbLoaderComma <T>(DbDebugItem <T> debug, AttributeList list, DbIOItems.DbCommaFunctionDelegate <T> function, TextFileHelper.TextFileHelperGetterDelegate getter, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in getter(FtpHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    if (!addAutomatically)
                    {
                        T id = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                        if (!table.ContainsKey(id))
                        {
                            TkDictionary <T, string[]> phantomTable;

                            if (!debug.AbsractDb.Attached.ContainsKey("Phantom." + debug.DbSource.Filename))
                            {
                                phantomTable = new TkDictionary <T, string[]>();
                                debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename] = phantomTable;
                            }
                            else
                            {
                                phantomTable = (TkDictionary <T, string[]>)debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename];
                            }

                            phantomTable[id] = elements;
                            continue;
                        }
                    }

                    function(debug, list, elements, table);
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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);
            }
        }
        public static void DbItemGroups <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes)
            {
                db.Attached[attribute.DisplayName] = false;
            }

            if (debug.FileType == FileType.Txt)
            {
                if (db.Attached["FromUserRawInput"] != null && (bool)db.Attached["FromUserRawInput"])
                {
                    _loadItemsGroupdDb(db, debug.FilePath);
                    return;
                }

                using (StreamReader reader = new StreamReader(File.OpenRead(debug.FilePath))) {
                    string line;

                    while (!reader.EndOfStream)
                    {
                        line = reader.ReadLine();

                        if (line != null && line.StartsWith("import: "))
                        {
                            string dbPath = AllLoaders.DetectPathAll(line.Replace("import: ", ""));

                            if (dbPath == null)
                            {
                                ErrorHandler.HandleException("Couldn't find the file '" + line.Replace("import: ", "") + "'.");
                            }
                            else
                            {
                                db.Attached[dbPath] = new Tuple <string, HashSet <int> >(line.Replace("import: ", ""), new HashSet <int>());
                                _loadItemsGroupdDb(db, dbPath);
                            }
                        }
                    }
                }
            }
            else if (debug.FileType == FileType.Conf)
            {
                ItemGroupParser itemHelper = new ItemGroupParser();
                Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items);
                int index = ServerItemAttributes.AegisName.Index;
                var table = db.Table;

                var items = itemsDb.FastItems;

                // The reverse table is used for an optimization (~3 seconds to ~50 ms)
                // All the items are stored in a dictionary by their name instead of their ID
                TkDictionary <string, int> reverseTable = new TkDictionary <string, int>();

                foreach (var item in items)
                {
                    reverseTable[item.GetStringValue(index).ToLowerInvariant()] = item.GetKey <int>();
                }

#if SDE_DEBUG
                Z.StopAndRemoveWithoutDisplay(-1);
                Z.StopAndRemoveWithoutDisplay(-2);
                Z.StopAndRemoveWithoutDisplay(-3);
                CLHelper.CR(-2);
#endif
                foreach (string elements in TextFileHelper.GetElementsByParenthesis(File.ReadAllBytes(debug.FilePath)))
                {
#if SDE_DEBUG
                    CLHelper.CS(-2);
                    CLHelper.CR(-1);
                    CLHelper.CR(-3);
#endif
                    if (!itemHelper.Init(debug, elements))
                    {
                        return;
                    }
#if SDE_DEBUG
                    CLHelper.CS(-3);
#endif

                    try {
                        Tuple tupleItem = itemsDb.TryGetTuple(reverseTable[itemHelper.Id.ToLowerInvariant()]);

                        if (tupleItem == null)
                        {
                            if (itemHelper.Id.StartsWith("ID"))
                            {
                                int ival;

                                if (Int32.TryParse(itemHelper.Id.Substring(2), out ival))
                                {
                                    tupleItem = itemsDb.TryGetTuple(ival);
                                }

                                if (tupleItem == null)
                                {
                                    debug.ReportIdException("Item ID '" + ival + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical);
                                    continue;
                                }
                            }

                            if (tupleItem == null)
                            {
                                debug.ReportIdException("Item ID '" + itemHelper.Id + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical);
                                continue;
                            }
                        }

                        TKey itemId = tupleItem.GetKey <TKey>();

                        if (!table.ContainsKey(itemId))
                        {
                            ReadableTuple <TKey> tuple = new ReadableTuple <TKey>(itemId, db.AttributeList);
                            tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >());
                            table.Add(itemId, tuple);
                        }

                        for (int i = 0; i < itemHelper.Quantities.Count; i++)
                        {
                            string onameId = itemHelper.Quantities[i].Item1;
                            string orate   = itemHelper.Quantities[i].Item2;
                            int    id      = 0;
                            int    rate;

                            tupleItem = itemsDb.TryGetTuple(reverseTable[onameId.ToLowerInvariant()]);

                            if (tupleItem == null)
                            {
                                if (onameId.StartsWith("ID"))
                                {
                                    if (!Int32.TryParse(onameId.Substring(2), out id))
                                    {
                                        debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical);
                                        continue;
                                    }
                                }
                                else
                                {
                                    debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical);
                                    continue;
                                }
                            }

                            int nameId = tupleItem == null ? id : tupleItem.GetKey <int>();
                            Int32.TryParse(orate, out rate);

                            Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table);

                            ReadableTuple <int> tuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList);
                            tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, rate);
                            dico[nameId] = tuple;
                        }
                    }
                    catch {
                        if (!debug.ReportIdException(itemHelper.Id))
                        {
                            return;
                        }
                    }
#if SDE_DEBUG
                    CLHelper.CS(-1);
                    CLHelper.CR(-2);
#endif
                }
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CS(-3);
                CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms, internal parser : " + CLHelper.CD(-3);
#endif
            }
        }
Exemple #10
0
        private void _setLuaFromFallback()
        {
            TkDictionary <int, ReadableTuple <int> > buffered = new TkDictionary <int, ReadableTuple <int> >();
            var overrideTable = new HashSet <string>();

            foreach (var headgear in _headgears)
            {
                if (!buffered.ContainsKey(headgear.Key))
                {
                    buffered[headgear.Key] = headgear;
                }
            }

            foreach (var pair in ItemIdToSprite)
            {
                overrideTable.Add(pair.Value);
            }

            foreach (var keyPair in _viewIdToSpriteFallback)
            {
                if (overrideTable.Contains(keyPair.Value))
                {
                    continue;
                }
                if (keyPair.Key <= 0)
                {
                    continue;
                }

                var    sTuple = buffered[keyPair.Key];
                string accessoryName;

                if (sTuple != null)
                {
                    accessoryName = LuaHelper.GetAccAegisNameFromTuple(sTuple);
                }
                else
                {
                    // No item associated with this view ID - these are NOT in the item_db tables
                    accessoryName = String.Format("UNREGISTERED_{0:0000}", keyPair.Key);
                }

                // Bogus entry - entry by number
                if (keyPair.Key.ToString(CultureInfo.InvariantCulture) == keyPair.Value)
                {
                    // Should NEVER happen
                    // Bogus entries are removed when the fallback values are read...
                    continue;
                }

                // Do not allow multiple ViewIDs to point towards the same sprite
                if (_luaSpriteToViewId.ContainsKey(keyPair.Value))
                {
                    continue;
                }

                // Do not allow empty named sprites
                if (keyPair.Value == "")
                {
                    continue;
                }

                _setEntry(keyPair.Key, accessoryName, keyPair.Value);
            }
        }