コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Tokeiburu/RSM2
        public void Test()
        {
            _primaryGrid.MouseMove  += new MouseEventHandler(_primaryGrid_MouseMove);
            _primaryGrid.MouseUp    += new MouseButtonEventHandler(_primaryGrid_MouseUp);
            _primaryGrid.KeyDown    += new KeyEventHandler(_primaryGrid_KeyDown);
            _primaryGrid.MouseWheel += new MouseWheelEventHandler(_primaryGrid_MouseWheel);

            _modelLight2.Content = new AmbientLight(Color.FromArgb(127, 127, 127, 127));
            _viewport3D1.Children.Add(new ModelVisual3D {
                Content = _mainModelGroup
            });

            if (_baseLoadData != null)
            {
                var data = _baseLoadData[0].Split(' ').Select(p => p.Trim(' ', ',')).ToList();

                _distance     = Single.Parse(data[0]);
                _angleXRad    = FormatConverters.DoubleConverter(data[1]);
                _angleYDegree = FormatConverters.DoubleConverter(data[2]);
                _lookAt       = new Vector3D(FormatConverters.DoubleConverter(data[3]), FormatConverters.DoubleConverter(data[4]), FormatConverters.DoubleConverter(data[5]));

                _animationFrame      = Int32.Parse(_baseLoadData[1]);
                _animationStartState = _baseLoadData[2];
            }

            UpdateCamera();
            new Thread(_animation).Start();
        }
コード例 #2
0
        private void _addRange()
        {
            var tab = _tab.To <int>();

            var range = FormatConverters.IntOrHexConverter(_tbRange.Text);
            var from  = FormatConverters.IntOrHexConverter(_tbFrom.Text);
            var table = tab.GetDb <int>((ServerDbs)_destTable.SelectedItem).Table;

            try {
                table.Commands.Begin();

                for (int i = 0; i < range; i++)
                {
                    var tuple = new ReadableTuple <int>(i + from, tab.DbComponent.AttributeList);

                    if (_based != null)
                    {
                        tuple.Copy(_based);
                        tuple.SetRawValue(0, i + from);
                    }

                    tuple.Added = true;
                    table.Commands.AddTuple(i + from, tuple);
                }
            }
            catch (Exception err) {
                table.Commands.CancelEdit();
                ErrorHandler.HandleException(err);
            }
            finally {
                table.Commands.End();
                tab.Filter();
            }
        }
コード例 #3
0
            public T ConvertFrom <T>(Database.Tuple source, object value)
            {
                if (typeof(T) == typeof(int))
                {
                    if (value == null)
                    {
                        return((T)(object)-1);
                    }

                    string val2 = (string)value;

                    if (val2 == "")
                    {
                        return((T)(object)-1);
                    }

                    if (val2.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                    {
                        return((T)(object)FormatConverters.IntOrHexConverter(val2));
                    }

                    return((T)(object)Int32.Parse(val2));
                }

                if (value == null)
                {
                    return((T)(object)"");
                }

                string val = (string)value;

                return((T)(object)val.Replace("0x", "").Replace("0X", ""));
            }
コード例 #4
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("}");
            }
        }
コード例 #5
0
        public int @int(object obj)
        {
            if (obj is int)
            {
                return((int)obj);
            }

            return(FormatConverters.IntOrHexConverter(obj.ToString()));
        }
コード例 #6
0
ファイル: ReadableTuple.cs プロジェクト: zdurexz/RagnarokSDE
        public int GetIntNoThrow(DbAttribute attibute)
        {
            object obj = GetValue(attibute.Index);

            if (obj is int)
            {
                return((int)obj);
            }
            return(FormatConverters.IntOrHexConverter((string)obj));
        }
コード例 #7
0
ファイル: ReadableTuple.cs プロジェクト: zdurexz/RagnarokSDE
        public int GetIntNoThrow(int index)
        {
            object obj = GetValue(index);

            if (obj is int)
            {
                return((int)obj);
            }
            return(FormatConverters.IntOrHexConverter((string)obj));
        }
コード例 #8
0
        public string hex(object obj)
        {
            if (obj is string)
            {
                return((string)obj);
            }

            int v = FormatConverters.IntOrHexConverter(obj.ToString());

            return("0x" + v.ToString("X"));
        }
コード例 #9
0
        public static void TrySetAttack(ReadableTuple <int> tuple, StringBuilder builder)
        {
            var atk1 = FormatConverters.IntOrHexConverter(tuple.GetValue <string>(ServerMobAttributes.Atk1));
            var atk2 = FormatConverters.IntOrHexConverter(tuple.GetValue <string>(ServerMobAttributes.Atk2));

            if (atk1 == atk2 && atk1 == 0)
            {
                return;
            }

            builder.AppendLine("\tAttack: [" + atk1 + ", " + (atk2 - atk1) + "]");
        }
コード例 #10
0
        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}");
            }
        }
コード例 #11
0
        private string _getTextSearch(DbAttribute att)
        {
            var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

            if (selected != null)
            {
                var tuple = selected._listView.SelectedItem as Database.Tuple;

                if (tuple != null)
                {
                    if (att.DataType == typeof(bool))
                    {
                        return("[" + att.GetQueryName() + "] == " + tuple.GetValue <string>(att));
                    }
                    else if (att.DataType.BaseType == typeof(Enum) || att.DataType == typeof(int))
                    {
                        return("[" + att.GetQueryName() + "] == " + tuple.GetValue <int>(att));
                    }
                    else
                    {
                        string value = tuple.GetRawValue <string>(att.Index);

                        if (FormatConverters.LongOrHexConverter(value) > 0 || value == "0x0" || value == "0")
                        {
                            return("[" + att.GetQueryName() + "] == " + value);
                        }
                        else
                        {
                            return("[" + att.GetQueryName() + "] contains \"" + value + "\"");
                        }
                    }
                }
                else
                {
                    if (att.DataType == typeof(bool))
                    {
                        return("[" + att.GetQueryName() + "] == true");
                    }
                    else
                    {
                        return("[" + att.GetQueryName() + "] == 0");
                    }
                }
            }

            return("");
        }
コード例 #12
0
        private void _update()
        {
            try {
                int flag = 0;

                foreach (CheckBox box in _boxes)
                {
                    if (box.IsChecked == true)
                    {
                        flag += (int)box.Tag;
                    }
                }

                _override = FormatConverters.IntOrHexConverter(_tbOverride.Text);
                _flag     = flag;
                OnValueChanged();
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
コード例 #13
0
        public static List <Job> GetJobsFromHex(string hexValue, int upper)
        {
            JobGroup group = JobGroup.Get(upper);
            int      jobId = FormatConverters.IntOrHexConverter(hexValue);

            //if (jobId < 0)
            //	jobId ^= -1;

            List <Job> jobs = new List <Job>();

            jobs.AddRange(_restrict(jobId, Novice.Id, group));
            jobs.AddRange(_restrict(jobId, Taekwon.Id, group));
            jobs.AddRange(_restrict(jobId, SoulLinker.Id, group));
            jobs.AddRange(_restrict(jobId, StarGladiator.Id, group));
            jobs.AddRange(_restrict(jobId, Gunslinger.Id, group));
            jobs.AddRange(_restrict(jobId, Ninja.Id, group));
            jobs.AddRange(_restrict(jobId, Swordman.Id, group));
            jobs.AddRange(_restrict(jobId, Acolyte.Id, group));
            jobs.AddRange(_restrict(jobId, Mage.Id, group));
            jobs.AddRange(_restrict(jobId, Archer.Id, group));
            jobs.AddRange(_restrict(jobId, Merchant.Id, group));
            jobs.AddRange(_restrict(jobId, Thief.Id, group));
            jobs.AddRange(_restrict(jobId, Knight.Id, group));
            jobs.AddRange(_restrict(jobId, Priest.Id, group));
            jobs.AddRange(_restrict(jobId, Wizard.Id, group));
            jobs.AddRange(_restrict(jobId, Hunter.Id, group));
            jobs.AddRange(_restrict(jobId, Blacksmith.Id, group));
            jobs.AddRange(_restrict(jobId, Assassin.Id, group));
            jobs.AddRange(_restrict(jobId, Crusader.Id, group));
            jobs.AddRange(_restrict(jobId, Monk.Id, group));
            jobs.AddRange(_restrict(jobId, Sage.Id, group));
            jobs.AddRange(_restrict(jobId, BardDancer.Id, group));
            jobs.AddRange(_restrict(jobId, Alchemist.Id, group));
            jobs.AddRange(_restrict(jobId, Rogue.Id, group));

            return(jobs.Distinct().ToList());
        }
コード例 #14
0
            public T ConvertFrom <T>(Database.Tuple source, object value)
            {
                if (value == null)
                {
                    return((T)(object)"");
                }

                string val = (string)value;

                if (val.StartsWith("0x") || val.StartsWith("0X"))
                {
                    int ival = val.Length > 2 ? Convert.ToInt32(val, 16) : 0;

                    if (typeof(T) == typeof(int))
                    {
                        return((T)(object)ival);
                    }

                    if (typeof(T) == typeof(string))
                    {
                        return((T)(object)ival.ToString(CultureInfo.InvariantCulture));
                    }
                }

                if (typeof(T) == typeof(int))
                {
                    return((T)(object)FormatConverters.IntOrHexConverter(val));
                }

                if (typeof(T) == typeof(string))
                {
                    return((T)(object)val);
                }

                throw new InvalidCastException("Couldn't convert '" + value + "' to type of " + typeof(T) + ".");
            }
コード例 #15
0
        private void _findClientItemErrors(List <ValidationErrorView> errors)
        {
            var itemDb  = _database.GetMetaTable <int>(ServerDbs.Items);
            var citemDb = _database.GetMetaTable <int>(ServerDbs.CItems);

            int current      = 0;
            int totalEntries = citemDb.FastItems.Count;

            Dictionary <int, int> viewIdToWepClass = _getWeaponClasses();

            //Expansion_Weapon_IDs
            foreach (var citem in citemDb.FastItems)
            {
                AProgress.IsCancelling(this);
                Progress = (float)current / totalEntries * 100f;
                current++;

                var sitem = itemDb.TryGetTuple(citem.Key);

                if (sitem == null)
                {
                    continue;
                }

                var itemType = sitem.GetValue <TypeType>(ServerItemAttributes.Type);

                if (itemType == TypeType.Weapon || itemType == TypeType.Armor)
                {
                    if (itemType == TypeType.Armor && !ItemParser.IsArmorType(sitem))
                    {
                        if (itemType == TypeType.Armor)
                        {
                            itemType = TypeType.Weapon;
                        }
                        else
                        {
                            itemType = TypeType.Armor;
                        }
                    }
                }

                var parameters = citem.GetValue <ParameterHolder>(ClientItemAttributes.Parameters);

                if (parameters != null)
                {
                    foreach (var param in ParameterHolder.KnownItemParameters)
                    {
                        try {
                            if (parameters.Values.ContainsKey(param))
                            {
                                var value = parameters.Values[param];

                                if (param == ParameterHolderKeys.Class && SdeAppConfiguration.VaCiClass)
                                {
                                    var sViewId  = sitem.GetIntNoThrow(ServerItemAttributes.ClassNumber);
                                    var location = sitem.GetIntNoThrow(ServerItemAttributes.Location);

                                    int cViewId;

                                    switch (itemType)
                                    {
                                    case TypeType.Weapon:
                                        var twoHanded        = (location & 34) == 34;
                                        var isWeaponLocation = (location & 2) != 0;

                                        if (!isWeaponLocation)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemLocation: server Location requires the 'Weapon' flag.", ServerDbs.Items, this));
                                        }

                                        ItemGeneratorEngine.WeaponTypeToViewId.TryGetValue(value, out cViewId);

                                        if (sViewId < 0)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: server View ID cannot be below 0.", ServerDbs.Items, this));
                                            continue;
                                        }

                                        if (sViewId >= ItemGeneratorEngine.WeaponTypes.Count)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: unknown server View ID, custom weapon?", ServerDbs.Items, this));
                                            continue;
                                        }

                                        if (cViewId == 0)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: found class '" + value + "', expected '" + ItemGeneratorEngine.WeaponTypes[sViewId] + "'", ServerDbs.CItems, this));
                                        }
                                        else if (cViewId != sViewId)
                                        {
                                            if (twoHanded)
                                            {
                                                if (ItemGeneratorEngine.TwoHandedWeapons.Contains(sViewId))
                                                {
                                                    errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: found class '" + value + "', expected '" + ItemGeneratorEngine.WeaponTypes[sViewId] + "'", ServerDbs.CItems, this));
                                                }
                                                else
                                                {
                                                    errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: found class '" + value + "', expected '" + ItemGeneratorEngine.WeaponTypes[sViewId] + "'. The server View ID doesn't belong to a two-handed weapon class.", ServerDbs.CItems, this));
                                                }
                                            }
                                            else
                                            {
                                                if (!ItemGeneratorEngine.TwoHandedWeapons.Contains(sViewId))
                                                {
                                                    errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: found class '" + value + "', expected '" + ItemGeneratorEngine.WeaponTypes[sViewId] + "'", ServerDbs.CItems, this));
                                                }
                                                else
                                                {
                                                    errors.Add(new CiError(ValidationErrors.CiItemClassUnknown, citem.Key, "ItemDescription: found class '" + value + "', expected '" + ItemGeneratorEngine.WeaponTypes[sViewId] + "'. The server View ID belongs to a two-handed weapon class.", ServerDbs.CItems, this));
                                                }
                                            }
                                        }

                                        break;

                                    default:

                                        break;
                                    }
                                }
                                else if (param == ParameterHolderKeys.Attack && SdeAppConfiguration.VaCiAttack)
                                {
                                    int ival;
                                    if (Int32.TryParse(value, out ival))
                                    {
                                        var sval = sitem.GetIntNoThrow(ServerItemAttributes.Attack);
                                        var name = sitem.GetValue <string>(ServerItemAttributes.Name);

                                        if (name.EndsWith(" Box"))
                                        {
                                            continue;
                                        }

                                        if (ival != sval)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiAttack, citem.Key, "Attack: found '" + value + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                        }
                                    }
                                    else
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiParseError, citem.Key, "Parse: failed to parse Attack field, found '" + value + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.Defense && SdeAppConfiguration.VaCiDefense)
                                {
                                    int ival;
                                    if (Int32.TryParse(value, out ival))
                                    {
                                        var sval = sitem.GetIntNoThrow(ServerItemAttributes.Defense);
                                        if (ival != sval)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiDefense, citem.Key, "Defense: found '" + value + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                        }
                                    }
                                    else
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiParseError, citem.Key, "Parse: failed to parse Defense field, found '" + value + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.Property && SdeAppConfiguration.VaCiProperty)
                                {
                                    var          script = sitem.GetValue <string>(ServerItemAttributes.Script);
                                    const string Bonus1 = "bonus bAtkEle";
                                    const string Bonus2 = "bonus bDefEle";

                                    if (script.Contains(Bonus1) || script.Contains(Bonus2))
                                    {
                                        var bonusScript = script.Contains(Bonus1) ? Bonus1 : Bonus2;

                                        int start = script.IndexOf(bonusScript, StringComparison.Ordinal) + bonusScript.Length;
                                        int end   = script.IndexOf(";", start, StringComparison.Ordinal);

                                        if (end < 0)
                                        {
                                            end = script.Length;
                                        }

                                        var bonus = script.Substring(start, end - start).Trim(',', ' ', ';');

                                        if (bonus.Length > 4)
                                        {
                                            var element = bonus.Substring(4);

                                            if (element != value)
                                            {
                                                if (value == "Shadow" && element == "Dark")
                                                {
                                                }
                                                else
                                                {
                                                    errors.Add(new CiError(ValidationErrors.CiProperty, citem.Key, "Property: found '" + value + "', expected '" + element + "'.", ServerDbs.CItems, this));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (value != "Neutral")
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiProperty, citem.Key, "Property: found '" + value + "', expected no element or Neutral.", ServerDbs.CItems, this));
                                        }
                                    }
                                }
                                else if (param == ParameterHolderKeys.RequiredLevel && SdeAppConfiguration.VaCiRequiredLevel)
                                {
                                    int ival;
                                    if (Int32.TryParse(value, out ival))
                                    {
                                        var sval = sitem.GetIntNoThrow(ServerItemAttributes.EquipLevel);
                                        if (ival != sval)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiEquipLevel, citem.Key, "EquipLevel: found '" + value + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                        }
                                    }
                                    else
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiParseError, citem.Key, "Parse: failed to parse EquipLevel field, found '" + value + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.WeaponLevel && SdeAppConfiguration.VaCiWeaponLevel)
                                {
                                    int ival;

                                    if (Int32.TryParse(value, out ival))
                                    {
                                        var name = sitem.GetValue <string>(ServerItemAttributes.Name);
                                        var sval = sitem.GetIntNoThrow(ServerItemAttributes.WeaponLevel);

                                        if (name.EndsWith(" Box"))
                                        {
                                            continue;
                                        }

                                        if (ival != sval)
                                        {
                                            errors.Add(new CiError(ValidationErrors.CiWeaponLevel, citem.Key, "WeaponLevel: found '" + value + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                        }
                                    }
                                    else
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiParseError, citem.Key, "Parse: failed to parse WeaponLevel field, found '" + value + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.Weight && SdeAppConfiguration.VaCiWeight)
                                {
                                    int ival = (int)(FormatConverters.SingleConverter(value) * 10);

                                    var sval = sitem.GetIntNoThrow(ServerItemAttributes.Weight);
                                    if (ival != sval)
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiWeight, citem.Key, "Weight: found '" + ival + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if ((param == ParameterHolderKeys.Location || param == ParameterHolderKeys.EquippedOn) && SdeAppConfiguration.VaCiLocation)
                                {
                                    var name = sitem.GetValue <string>(ServerItemAttributes.Name);

                                    // Do not scan rental items
                                    if (name.EndsWith(" Box"))
                                    {
                                        continue;
                                    }

                                    string[] items = value.Split(',', '/', '-', '&').Select(p => p.Trim(' ')).ToArray();
                                    int      ival  = 0;

                                    foreach (string item in items)
                                    {
                                        if (item.ToLower() == "lower")
                                        {
                                            ival |= 1;
                                        }
                                        if (item.ToLower() == "mid" || item.ToLower() == "middle")
                                        {
                                            ival |= 512;
                                        }
                                        if (item.ToLower() == "upper")
                                        {
                                            ival |= 256;
                                        }
                                        if (item.ToLower() == "all slot")
                                        {
                                            ival |= 1023;
                                        }
                                    }

                                    var sval = sitem.GetIntNoThrow(ServerItemAttributes.Location);

                                    if ((sval & 7168) != 0)
                                    {
                                        // It's a costume ;x!
                                        ival = 0;

                                        foreach (string item in items)
                                        {
                                            if (item.ToLower() == "lower")
                                            {
                                                ival |= 4096;
                                            }
                                            if (item.ToLower() == "mid" || item.ToLower() == "middle")
                                            {
                                                ival |= 2048;
                                            }
                                            if (item.ToLower() == "upper")
                                            {
                                                ival |= 1024;
                                            }
                                        }
                                    }

                                    if (ival != sval)
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiLocation, citem.Key, "Location: found '" + ival + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.CompoundOn && SdeAppConfiguration.VaCiCompoundOn)
                                {
                                    var valueLower = value.ToLower();
                                    int location   = 0;

                                    switch (valueLower)
                                    {
                                    case "weapon":
                                        location = 2;
                                        break;

                                    case "headgear":
                                        location = 769;
                                        break;

                                    case "armor":
                                        location = 16;
                                        break;

                                    case "shield":
                                        location = 32;
                                        break;

                                    case "garment":
                                        location = 4;
                                        break;

                                    case "accessory":
                                        location = 136;
                                        break;

                                    case "shoes":
                                    case "footwear":
                                    case "foot gear":
                                    case "footgear":
                                        location = 64;
                                        break;

                                    default:
                                        errors.Add(new CiError(ValidationErrors.CiParseError, citem.Key, "CompoundOn: found '" + value + "'.", ServerDbs.CItems, this));
                                        break;
                                    }

                                    var sval = sitem.GetIntNoThrow(ServerItemAttributes.Location);

                                    if ((location & sval) != sval)
                                    {
                                        errors.Add(new CiError(ValidationErrors.CiCompoundOn, citem.Key, "CompoundOn: found '" + location + "', expected '" + sval + "'.", ServerDbs.CItems, this));
                                    }
                                }
                                else if (param == ParameterHolderKeys.ApplicableJob && SdeAppConfiguration.VaCiJob)
                                {
                                    //var jobs = JobList.GetApplicableJobs(value);
                                    //var jobHex = JobList.GetHexJob(jobs);
                                    //
                                    //var sJobHex = "0x" + sitem.GetValue<string>(ServerItemAttributes.ApplicableJob);
                                    //jobs = JobList.GetApplicableJobsFromHex(sJobHex);
                                    //sJobHex = JobList.GetHexJob(jobs);
                                    //
                                    //if (jobHex != sJobHex) {
                                    //	errors.Add(new CiError(ValidationErrors.CiCompoundOn, citem.Key, "ApplicableJob: found '" + jobHex + "', expected '" + sJobHex + "'.", ServerDbs.CItems, this));
                                    //}
                                }
                            }
                        }
                        catch {
                            errors.Add(new CiError(ValidationErrors.Generic, citem.Key, "Failed to analyse property '" + param + "'.", ServerDbs.Items, this));
                        }
                    }
                }
                // End of parameters

                if (itemType == TypeType.Weapon && SdeAppConfiguration.VaCiItemRange)
                {
                    var sVal = sitem.GetIntNoThrow(ServerItemAttributes.ClassNumber);

                    if (sVal < 24 && sVal > 0)
                    {
                        var range = _ranges[sVal];
                        var id    = sitem.Key;

                        bool found = false;

                        for (int i = 0; i < range.Length; i += 2)
                        {
                            if (range[i] < 0)
                            {
                                errors.Add(new CiError(ValidationErrors.CiItemRange, citem.Key, "ItemRange: found weapon class '" + sVal + "', which does not have any ID range.", ServerDbs.Items, this));
                                found = true;
                                break;
                            }

                            if (range[i] <= id && id <= range[i + 1])
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            string idRange = "";

                            for (int i = 0; i < range.Length; i += 2)
                            {
                                if (i > 0)
                                {
                                    idRange += ", ";
                                }

                                idRange += range[i] + "-" + range[i + 1];
                            }

                            errors.Add(new CiError(ValidationErrors.CiItemRange, citem.Key, "ItemRange: found weapon class '" + sVal + "', which has an ID range of [" + idRange + "].", ServerDbs.Items, this));
                        }
                    }
                }

                if (SdeAppConfiguration.VaCiNumberOfSlots)
                {
                    var sVal = sitem.GetIntNoThrow(ServerItemAttributes.NumberOfSlots);
                    var cVal = citem.GetIntNoThrow(ClientItemAttributes.NumberOfSlots);

                    if (sVal != cVal)
                    {
                        errors.Add(new CiError(ValidationErrors.CiNumOfSlots, citem.Key, "NumberOfSlots: found '" + cVal + "', expected '" + sVal + "'.", ServerDbs.CItems, this));
                    }

                    if (!ItemParser.IsArmorType(sitem) && !ItemParser.IsWeaponType(sitem))
                    {
                        if (sVal > 0)
                        {
                            errors.Add(new CiError(ValidationErrors.CiNumOfSlots, citem.Key, "NumberOfSlots: found '" + sVal + "', but the server item type is neither an armor or a weapon..", ServerDbs.Items, this));
                        }
                    }
                }

                if (SdeAppConfiguration.VaCiViewId)
                {
                    var sVal = sitem.GetIntNoThrow(ServerItemAttributes.ClassNumber);
                    var cVal = citem.GetIntNoThrow(ClientItemAttributes.ClassNumber);

                    if (sVal != cVal)
                    {
                        var nVal = cVal;

                        if (cVal > 24)
                        {
                            if (viewIdToWepClass.ContainsKey(cVal))
                            {
                                nVal = viewIdToWepClass[cVal];
                            }
                        }

                        if (sVal != nVal)
                        {
                            if (nVal != cVal)
                            {
// && nVal + 1 == sVal) {
                            }
                            else
                            {
                                bool showError = true;

                                if (cVal == 0)
                                {
                                    if ((citem.Key >= 18000 && citem.Key <= 18099) ||
                                        (citem.Key >= 13260 && citem.Key <= 13290))
                                    {
                                        showError = false;
                                    }
                                }

                                if (showError)
                                {
                                    errors.Add(new CiError(ValidationErrors.CiViewId, citem.Key, "ClassNumber: found '" + cVal + "', class '" + nVal + "', expected '" + sVal + "'.", ServerDbs.CItems, this));
                                }
                            }
                        }
                    }
                }

                if (SdeAppConfiguration.VaCiIsCard)
                {
                    var sVal = itemType;
                    var cVal = citem.GetValue <bool>(ClientItemAttributes.IsCard);

                    if ((sVal == TypeType.Card || cVal) && (sVal != TypeType.Card || !cVal))
                    {
                        errors.Add(new CiError(ValidationErrors.CiCardType, citem.Key, "TypeMismatch: client item IsCard '" + cVal + "', server type '" + sVal + "'.", ServerDbs.CItems, this));
                    }
                }

                if (SdeAppConfiguration.VaCiName)
                {
                    var sname = sitem.GetValue <string>(ServerItemAttributes.Name);
                    var cname = citem.GetValue <string>(ClientItemAttributes.IdentifiedDisplayName);

                    if (sname != cname)
                    {
                        int distance = Methods.LevenshteinDistance(sname, cname);

                        if (distance > 5)
                        {
                            errors.Add(new CiError(ValidationErrors.CiName, citem.Key, "NameMismatch: client name is '" + cname + "', server name is '" + sname + "', diff = " + distance + ".", ServerDbs.CItems, this));
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: DbIOMobs.cs プロジェクト: userid0/RagnarokSDE
        public static void WriteEntryYaml(StringBuilder builder, ReadableTuple <int> tuple, MetaTable <int> itemDb)
        {
            if (tuple != null)
            {
                builder.AppendLine("  - Id: " + tuple.GetKey <int>().ToString(CultureInfo.InvariantCulture));
                builder.AppendLine("    AegisName: " + tuple.GetValue <string>(ServerMobAttributes.AegisName));
                builder.AppendLine("    Name: " + DbIOUtils.QuoteCheck(tuple.GetValue <string>(ServerMobAttributes.IRoName)));

                if (tuple.GetValue <string>(ServerMobAttributes.IRoName) != tuple.GetValue <string>(ServerMobAttributes.KRoName))
                {
                    builder.AppendLine("    JapaneseName: " + DbIOUtils.QuoteCheck(tuple.GetValue <string>(ServerMobAttributes.KRoName)));
                }

                int value;
                //bool valueB;
                string valueS;
                //int type = 0;

                builder.AppendLine("    Level: " + tuple.GetValue <int>(ServerMobAttributes.Lv));

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Hp)) != 1)
                {
                    builder.AppendLine("    Hp: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Sp)) != 1)
                {
                    builder.AppendLine("    Sp: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Exp)) != 0)
                {
                    builder.AppendLine("    BaseExp: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.JExp)) != 0)
                {
                    builder.AppendLine("    JobExp: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.MvpExp)) != 0)
                {
                    builder.AppendLine("    MvpExp: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Atk1)) != 0)
                {
                    builder.AppendLine("    Attack: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Atk2)) != 0)
                {
                    builder.AppendLine("    Attack2: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Def)) != 0)
                {
                    builder.AppendLine("    Defense: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Mdef)) != 0)
                {
                    builder.AppendLine("    MagicDefense: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Str)) != 1)
                {
                    builder.AppendLine("    Str: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Agi)) != 1)
                {
                    builder.AppendLine("    Agi: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Vit)) != 1)
                {
                    builder.AppendLine("    Vit: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Int)) != 1)
                {
                    builder.AppendLine("    Int: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Dex)) != 1)
                {
                    builder.AppendLine("    Dex: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Luk)) != 1)
                {
                    builder.AppendLine("    Luk: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.AttackRange)) != 0)
                {
                    builder.AppendLine("    AttackRange: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.ViewRange)) != 0)
                {
                    builder.AppendLine("    SkillRange: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.ChaseRange)) != 0)
                {
                    builder.AppendLine("    ChaseRange: " + value);
                }

                //if ((value = tuple.GetValue<int>(ServerMobAttributes.Size)) != 0) {
                builder.AppendLine("    Size: " + Constants.ToString <SizeType>(tuple.GetValue <int>(ServerMobAttributes.Size)));
                //}

                builder.AppendLine("    Race: " + Constants.ToString <MobRaceType>(tuple.GetValue <int>(ServerMobAttributes.Race)));

                DbIOUtils.ExpandFlag <MobGroup2Type>(builder, tuple, "RaceGroups", ServerMobAttributes.RaceGroups, YamlParser.Indent4, YamlParser.Indent6);

                int elementLevel = tuple.GetValue <int>(ServerMobAttributes.Element) / 20;
                int element      = tuple.GetValue <int>(ServerMobAttributes.Element) % 20;

                switch (element)
                {
                case 0: builder.AppendLine("    Element: Neutral"); break;

                case 1: builder.AppendLine("    Element: Water"); break;

                case 2: builder.AppendLine("    Element: Earth"); break;

                case 3: builder.AppendLine("    Element: Fire"); break;

                case 4: builder.AppendLine("    Element: Wind"); break;

                case 5: builder.AppendLine("    Element: Poison"); break;

                case 6: builder.AppendLine("    Element: Holy"); break;

                case 7: builder.AppendLine("    Element: Dark"); break;

                case 8: builder.AppendLine("    Element: Ghost"); break;

                case 9: builder.AppendLine("    Element: Undead"); break;
                }

                builder.AppendLine("    ElementLevel: " + elementLevel);

                if ((value = tuple.GetValue <int>(ServerMobAttributes.MoveSpeed)) != 0)
                {
                    builder.AppendLine("    WalkSpeed: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.AttackDelay)) != 0)
                {
                    builder.AppendLine("    AttackDelay: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.AttackMotion)) != 0)
                {
                    builder.AppendLine("    AttackMotion: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.DamageMotion)) != 0)
                {
                    builder.AppendLine("    DamageMotion: " + value);
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.DamageTaken)) != 100)
                {
                    builder.AppendLine("    DamageTaken: " + value);
                }

                long mode = FormatConverters.LongOrHexConverter(tuple.GetValue <string>(ServerMobAttributes.NewMode));

                if ((mode & 0xB695) == 0xB695)
                {
                    builder.AppendLine("    Ai: 26");
                    mode &= ~0xB695;
                }
                else if ((mode & 0x8084) == 0x8084)
                {
                    builder.AppendLine("    Ai: 27");
                    mode &= ~0x8084;
                }
                else if ((mode & 0x7085) == 0x7085)
                {
                    builder.AppendLine("    Ai: 08");
                    mode &= ~0x7085;
                }
                else if ((mode & 0x3885) == 0x3885)
                {
                    builder.AppendLine("    Ai: 04");
                    mode &= ~0x3885;
                }
                else if ((mode & 0x3695) == 0x3695)
                {
                    builder.AppendLine("    Ai: 21");
                    mode &= ~0x3695;
                }
                else if ((mode & 0x3295) == 0x3295)
                {
                    builder.AppendLine("    Ai: 20");
                    mode &= ~0x3295;
                }
                else if ((mode & 0x3095) == 0x3095)
                {
                    builder.AppendLine("    Ai: 09");
                    mode &= ~0x3095;
                }
                else if ((mode & 0x308D) == 0x308D)
                {
                    builder.AppendLine("    Ai: 13");
                    mode &= ~0x308D;
                }
                else if ((mode & 0x2085) == 0x2085)
                {
                    builder.AppendLine("    Ai: 05");
                    mode &= ~0x2085;
                }
                else if ((mode & 0x108B) == 0x108B)
                {
                    builder.AppendLine("    Ai: 07");
                    mode &= ~0x108B;
                }
                else if ((mode & 0x1089) == 0x1089)
                {
                    builder.AppendLine("    Ai: 03");
                    mode &= ~0x1089;
                }
                else if ((mode & 0xA1) == 0xA1)
                {
                    builder.AppendLine("    Ai: 24");
                    mode &= ~0xA1;
                }
                else if ((mode & 0x91) == 0x91)
                {
                    builder.AppendLine("    Ai: 17");
                    mode &= ~0x91;
                }
                else if ((mode & 0x84) == 0x84)
                {
                    builder.AppendLine("    Ai: 10");
                    mode &= ~0x84;
                }
                else if ((mode & 0x83) == 0x83)
                {
                    builder.AppendLine("    Ai: 02");
                    mode &= ~0x83;
                }
                else if ((mode & 0x81) == 0x81)
                {
                    builder.AppendLine("    Ai: 01");
                    mode &= ~0x81;
                }
                else if ((mode & 0x1) == 0x1)
                {
                    builder.AppendLine("    Ai: 25");
                    mode &= ~0x1;
                }

                if ((value = tuple.GetValue <int>(ServerMobAttributes.Class)) != 0)
                {
                    builder.AppendLine("    Class: " + Constants.ToString <ClassType>(value));
                }

                if (mode > 0)
                {
                    builder.AppendLine("    Modes:");
                    if ((mode & 0x1) == 0x1)
                    {
                        builder.AppendLine("      CanMove: true");
                    }
                    if ((mode & 0x80) == 0x80)
                    {
                        builder.AppendLine("      CanAttack: true");
                    }
                    if ((mode & 0x40) == 0x40)
                    {
                        builder.AppendLine("      NoCast: true");
                    }
                    if ((mode & 0x2) == 0x2)
                    {
                        builder.AppendLine("      Looter: true");
                    }
                    if ((mode & 0x4) == 0x4)
                    {
                        builder.AppendLine("      Aggressive: true");
                    }
                    if ((mode & 0x8) == 0x8)
                    {
                        builder.AppendLine("      Assist: true");
                    }
                    if ((mode & 0x20) == 0x20)
                    {
                        builder.AppendLine("      NoRandomWalk: true");
                    }
                    if ((mode & 0x200) == 0x200)
                    {
                        builder.AppendLine("      CastSensorChase: true");
                    }
                    if ((mode & 0x10) == 0x10)
                    {
                        builder.AppendLine("      CastSensorIdle: true");
                    }
                    if ((mode & 0x800) == 0x800)
                    {
                        builder.AppendLine("      Angry: true");
                    }
                    if ((mode & 0x400) == 0x400)
                    {
                        builder.AppendLine("      ChangeChase: true");
                    }
                    if ((mode & 0x1000) == 0x1000)
                    {
                        builder.AppendLine("      ChangeTargetMelee: true");
                    }
                    if ((mode & 0x2000) == 0x2000)
                    {
                        builder.AppendLine("      ChangeTargetChase: true");
                    }
                    if ((mode & 0x4000) == 0x4000)
                    {
                        builder.AppendLine("      TargetWeak: true");
                    }
                    if ((mode & 0x8000) == 0x8000)
                    {
                        builder.AppendLine("      RandomTarget: true");
                    }
                    if ((mode & 0x20000) == 0x20000)
                    {
                        builder.AppendLine("      IgnoreMagic: true");
                    }
                    if ((mode & 0x10000) == 0x10000)
                    {
                        builder.AppendLine("      IgnoreMelee: true");
                    }
                    if ((mode & 0x100000) == 0x100000)
                    {
                        builder.AppendLine("      IgnoreMisc: true");
                    }
                    if ((mode & 0x40000) == 0x40000)
                    {
                        builder.AppendLine("      IgnoreRanged: true");
                    }
                    if ((mode & 0x400000) == 0x400000)
                    {
                        builder.AppendLine("      TeleportBlock: true");
                    }
                    if ((mode & 0x1000000) == 0x1000000)
                    {
                        builder.AppendLine("      FixedItemDrop: true");
                    }
                    if ((mode & 0x2000000) == 0x2000000)
                    {
                        builder.AppendLine("      Detector: true");
                    }
                    if ((mode & 0x200000) == 0x200000)
                    {
                        builder.AppendLine("      KnockBackImmune: true");
                    }
                    if ((mode & 0x4000000) == 0x4000000)
                    {
                        builder.AppendLine("      StatusImmune: true");
                    }
                    if ((mode & 0x8000000) == 0x8000000)
                    {
                        builder.AppendLine("      SkillImmune: true");
                    }
                    if ((mode & 0x80000) == 0x80000)
                    {
                        builder.AppendLine("      Mvp: true");
                    }
                }

                int stat = 0;

                for (int i = 0; i < 6; i += 2)
                {
                    stat += tuple.GetIntNoThrow(ServerMobAttributes.Mvp1ID.Index + i);
                }

                if (stat != 0)
                {
                    builder.AppendLine("    MvpDrops:");

                    for (int i = 0; i < 6; i += 2)
                    {
                        valueS = tuple.GetValue <string>(ServerMobAttributes.Mvp1ID.Index + i);

                        if (stat != 0 && valueS != "0" && valueS != "")
                        {
                            builder.AppendLine("      - Item: " + DbIOUtils.Id2Name(itemDb, ServerItemAttributes.AegisName, valueS));
                            builder.AppendLine("        Rate: " + tuple.GetValue <int>(ServerMobAttributes.Mvp1ID.Index + i + 1));

                            if ((valueS = tuple.GetValue <string>(ServerMobAttributes.Mvp1RandomOptionGroup.Index + (i / 2))) != "")
                            {
                                builder.AppendLine("        RandomOptionGroup: " + valueS);
                            }
                        }
                    }
                }

                stat = 0;

                for (int i = 0; i < 20; i += 2)
                {
                    stat += tuple.GetIntNoThrow(ServerMobAttributes.Drop1ID.Index + i);
                }

                if (stat != 0)
                {
                    builder.AppendLine("    Drops:");

                    for (int i = 0; i < 20; i += 2)
                    {
                        valueS = tuple.GetValue <string>(ServerMobAttributes.Drop1ID.Index + i);

                        if (stat != 0 && valueS != "0" && valueS != "")
                        {
                            builder.AppendLine("      - Item: " + DbIOUtils.Id2Name(itemDb, ServerItemAttributes.AegisName, valueS));
                            builder.AppendLine("        Rate: " + tuple.GetValue <int>(ServerMobAttributes.Drop1ID.Index + i + 1));

                            if ((valueS = tuple.GetValue <string>(ServerMobAttributes.Drop1Flags.Index + (i / 2))) != "" && valueS != null)
                            {
                                if (FormatConverters.BooleanConverter(valueS))
                                {
                                    builder.AppendLine("        StealProtected: true");
                                }
                            }

                            if ((valueS = tuple.GetValue <string>(ServerMobAttributes.Drop1RandomOptionGroup.Index + (i / 2))) != "")
                            {
                                builder.AppendLine("        RandomOptionGroup: " + valueS);
                            }
                        }
                    }
                }
            }
        }
コード例 #17
0
        public static GroupCommand <TKey, ReadableTuple <TKey> > Generate <TKey>(ReadableTuple <TKey> item, bool execute)
        {
            GroupCommand <TKey, ReadableTuple <TKey> > commands = GroupCommand <TKey, ReadableTuple <TKey> > .Make();

            WebClient client = new WebClient();

            byte[] data;

            try {
                data = client.DownloadData("https://www.divine-pride.net/database/monster/" + item.Key);
            }
            catch {
                return(null);
            }

            string content = Encoding.Default.GetString(data);
            int    index   = content.IndexOf("Drop chance", 0, System.StringComparison.Ordinal);

            if (index < 0)
            {
                return(null);
            }

            HashSet <int> used = new HashSet <int>();

            var legentRestart = content.IndexOf("<legend>RE:Start</legend>", 0);

            while (true)
            {
                index = content.IndexOf("&nbsp;", index);

                if (index < -1)
                {
                    break;
                }

                if (legentRestart > -1 && index > legentRestart)
                {
                    break;
                }

                int start = index + "&nbsp;".Length;
                int end   = content.IndexOf("\r", start);
                index = end;

                string numberString = content.Substring(start, end - start);

                int nameid = 0;

                if (Int32.TryParse(numberString, out nameid))
                {
                    // find drop rate
                    int spanStart = content.IndexOf("<span>", end) + "<span>".Length;
                    int spanEnd   = content.IndexOf("%", spanStart);

                    string chanceString = content.Substring(spanStart, spanEnd - spanStart);

                    decimal value = (decimal)FormatConverters.SingleConverter(chanceString);

                    if (value > 0)
                    {
                        int  chance = (int)((decimal)value * 100);
                        bool found  = false;
                        int  free   = -1;

                        for (int i = ServerMobAttributes.Drop1ID.Index; i <= ServerMobAttributes.DropCardid.Index; i += 2)
                        {
                            if (used.Contains(i))
                            {
                                continue;
                            }

                            int nameidSource = item.GetValue <int>(i);
                            int chanceSource = item.GetValue <int>(i + 1);

                            if (nameidSource == 0 && free == -1)
                            {
                                free = i;
                            }

                            if (nameidSource != nameid)
                            {
                                continue;
                            }

                            found = true;
                            used.Add(i);

                            if (chanceSource == chance)
                            {
                                break;
                            }

                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[i + 1], chance));
                            break;
                        }

                        if (!found)
                        {
                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[free], nameid));
                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[free + 1], chance));
                            used.Add(free);
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            {
                //string content = Encoding.Default.GetString(data);
                int start   = 0;
                int end     = 0;
                int atk1    = 0;
                int atk2    = 0;
                int matk1   = 0;
                int matk2   = 0;
                int level   = item.GetValue <int>(ServerMobAttributes.Lv);
                int strStat = item.GetValue <int>(ServerMobAttributes.Str);
                int intStat = item.GetValue <int>(ServerMobAttributes.Int);

                if (!MoveTo(content, "<td class=\"right\">", ref start, ref end))                 // mob id
                {
                    return(null);
                }

                MoveForward(ref start, ref end);

                try {
                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // mob level
                        level = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Lv, level));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // HP
                        //commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.Lv, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Attack
                        string span = ReadSpan(content, ref start, ref end);
                        span = span.Replace(",", "").Replace(" ", "");
                        string[] dataAtk = span.Split('-');
                        atk1 = Int32.Parse(dataAtk[0]);
                        atk2 = Int32.Parse(dataAtk[1]);
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Magic attack
                        string span = ReadSpan(content, ref start, ref end);
                        span = span.Replace(",", "").Replace(" ", "");
                        string[] dataAtk = span.Split('-');
                        matk1 = Int32.Parse(dataAtk[0]);
                        matk2 = Int32.Parse(dataAtk[1]);
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Speed
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Range
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Hit
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Flee
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Def
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Def, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Mdef
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Mdef, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Str
                        strStat = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Str, strStat));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Agi
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Agi, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Vit
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Vit, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Int
                        intStat = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Int, intStat));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Dex
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Dex, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Luk
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Luk, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    atk1  = (atk2 + atk1) / 2 - strStat - level;
                    matk1 = (matk1 + matk2) / 2 - intStat - level;

                    int v1 = Math.Abs(item.GetValue <int>(ServerMobAttributes.Atk1) - atk1);
                    int v2 = Math.Abs((item.GetValue <int>(ServerMobAttributes.Atk2) - item.GetValue <int>(ServerMobAttributes.Atk1)) - matk1);

                    if (!execute)
                    {
                        if (v1 > 1 || v2 > 1)
                        {
                            Console.WriteLine("Invalid atk/matk for " + item.Key);
                        }

                        return(null);
                    }

                    if (level > 0)
                    {
                        // Look up experience
                        start = content.IndexOf("id=\"experience\"", System.StringComparison.Ordinal);
                        int tbStart = content.IndexOf("<tbody>", index);
                        int tbEnd   = content.IndexOf("</tbody>", tbStart);

                        while (end < tbEnd)
                        {
                            if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                            {
                                int lv = ReadInteger(content, ref end);
                                MoveForward(ref start, ref end);

                                if (lv == level)
                                {
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);

                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    int baseExp = ReadInteger(content, ref end);
                                    MoveForward(ref start, ref end);

                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    int jobExp = ReadInteger(content, ref end);
                                    MoveForward(ref start, ref end);

                                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Exp, baseExp));
                                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.JExp, jobExp));
                                    break;
                                }
                                else
                                {
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                }
                            }
                            else
                            {
                                MoveForward(ref start, ref end);
                            }
                        }
                    }

                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk1, atk1));
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk2, atk1 + matk1));
                }
                catch {
                    return(null);
                }
            }

            //while (true) {
            //	index = content.IndexOf("&nbsp;", index);
            //
            //	if (index < -1)
            //		break;
            //
            //	int start = index + "&nbsp;".Length;
            //	int end = content.IndexOf("\r", start);
            //	index = end;
            //
            //	string numberString = content.Substring(start, end - start);
            //
            //	int nameid = 0;
            //
            //	if (Int32.TryParse(numberString, out nameid)) {
            //		// find drop rate
            //		int spanStart = content.IndexOf("<span>", end) + "<span>".Length;
            //		int spanEnd = content.IndexOf("%", spanStart);
            //
            //		string chanceString = content.Substring(spanStart, spanEnd - spanStart);
            //
            //		decimal value = (decimal)FormatConverters.SingleConverter(chanceString);
            //
            //		if (value > 0) {
            //			int chance = (int)((decimal)value * 100);
            //			bool found = false;
            //			int free = -1;
            //
            //			for (int i = ServerMobAttributes.Drop1ID.Index; i <= ServerMobAttributes.DropCardid.Index; i += 2) {
            //				if (used.Contains(i))
            //					continue;
            //
            //				int nameidSource = item.GetValue<int>(i);
            //				int chanceSource = item.GetValue<int>(i + 1);
            //
            //				if (nameidSource == 0 && free == -1) {
            //					free = i;
            //				}
            //
            //				if (nameidSource != nameid)
            //					continue;
            //
            //				found = true;
            //				used.Add(i);
            //
            //				if (chanceSource == chance)
            //					break;
            //
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[i + 1], chance));
            //				break;
            //			}
            //
            //			if (!found) {
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[free], nameid));
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[free + 1], chance));
            //			}
            //		}
            //	}
            //	else {
            //		break;
            //	}
            //}

            if (commands.Commands.Count == 0)
            {
                return(null);
            }

            return(commands);
        }
コード例 #18
0
        public static void TrySetJobsYaml2(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, string defaultValue)
        {
            string val = "0x" + tuple.GetValue <string>(attribute);

            if (val == "0x")
            {
                builder.AppendLine("	Jobs: {");
                builder.AppendLine("		All: false");
                builder.AppendLine("	}");
                return;
            }

            if (val != "" && val != defaultValue && val.Length > 2 && val.ToLower() != "0xffffffff")
            {
                builder.AppendLine("	Jobs: {");

                int value = FormatConverters.IntOrHexConverter(val);

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

                uint guess    = 0;
                bool isExcept = false;

                // Take a guess!
                if (Job.IsExcept(value))
                {
                    isExcept = true;
                    guess    = 0xffffffff;

                    foreach (var job in DbIOItems.ItemDbJobsYaml3.Skip(1))
                    {
                        if ((value & job.Value) == job.Value)
                        {
                            guess &= ~(uint)job.Value;
                        }
                    }
                }
                else
                {
                    Z.F();

                    foreach (var job in DbIOItems.ItemDbJobsYaml3.Skip(1))
                    {
                        if ((value & job.Value) == job.Value)
                        {
                            guess |= (uint)job.Value;
                        }
                    }
                }

                if ((uint)value != guess)
                {
                    isExcept = !isExcept;
                }

                if (isExcept)
                {
                    value ^= -1;
                    builder.AppendLine("		All: true");

                    foreach (var job in DbIOItems.ItemDbJobsYaml2.Skip(1))
                    {
                        if ((value & job.Value) == job.Value)
                        {
                            builder.Append("		");
                            builder.Append(job.Key);
                            builder.AppendLine(": false");
                        }
                    }
                }
                else
                {
                    foreach (var job in DbIOItems.ItemDbJobsYaml2.Skip(1))
                    {
                        if ((value & job.Value) == job.Value)
                        {
                            builder.Append("		");
                            builder.Append(job.Key);
                            builder.AppendLine(": true");
                        }
                    }
                }

                builder.AppendLine("	}");
            }
        }
コード例 #19
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);
            }
        }
コード例 #20
0
        static FlagsManager()
        {
            try {
                FlagTypeData flagTypeData = null;

                string[] lines;

                if (File.Exists("def.txt"))
                {
                    lines = File.ReadAllLines("def.txt");
                }
                else
                {
                    lines = TextFileHelper.ReadAllLines(ApplicationManager.GetResource("def.txt")).ToArray();
                }

                foreach (var line in lines)
                {
                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    FlagDataProperty property = FlagDataProperty.None;

                    if (line.StartsWith("["))
                    {
                        var name = line.Trim('[', ']');

                        if (flagTypeData != null)
                        {
                            _flags[flagTypeData.Name] = flagTypeData;
                        }

                        flagTypeData = new FlagTypeData(name);
                    }
                    else if (flagTypeData != null)
                    {
                        var    data        = line.Split('\t');
                        var    name        = data[0];
                        long   value       = 0;
                        string description = null;

                        if (data[1] == "auto")
                        {
                            if (flagTypeData.LatestValue == 0)
                            {
                                value = 1;
                            }
                            else
                            {
                                value = flagTypeData.LatestValue << 1;
                            }

                            flagTypeData.LatestValue = value;
                        }
                        else if (!char.IsDigit(data[1][0]) && !data[1].StartsWith("0x") && !data[1].StartsWith("0X"))
                        {
                            try {
                                Condition cond      = ConditionLogic.GetCondition(data[1]);
                                var       predicate = cond.ToLong(flagTypeData);
                                flagTypeData.LatestValue = value = predicate();
                            }
                            catch {
                                ErrorHandler.HandleException("Unable to parse the flag definition for " + line);
                            }
                        }
                        else
                        {
                            flagTypeData.LatestValue = value = FormatConverters.LongOrHexConverter(data[1]);
                        }

                        if (data.Length > 2)
                        {
                            description = data[2];
                        }

                        if (data.Length > 3)
                        {
                            if (data[3] == "hide")
                            {
                                property |= FlagDataProperty.Hide;
                            }
                        }

                        flagTypeData.AddValue(new FlagData(name, value, description)
                        {
                            DataFlag = property
                        });
                    }
                }

                if (flagTypeData != null)
                {
                    _flags[flagTypeData.Name] = flagTypeData;
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
コード例 #21
0
ファイル: Condition.cs プロジェクト: zdurexz/RagnarokSDE
        public override Func <TValue, string, double> ToInt <TKey, TValue>(GTabSettings <TKey, TValue> settings, out bool isInt)
        {
            isInt = false;

            if (Value.StartsWith("[") && Value.EndsWith("]"))
            {
                string se = Value.Substring(1, Value.Length - 2);

                var  att       = settings.AttributeList.Find(se);
                bool?canDirect = null;

                if (att >= 0)
                {
                    return(new Func <TValue, string, double>((t, s) => {
                        int ival2;

                        if (canDirect == true)
                        {
                            try {
                                ival2 = t.GetValue <int>(att);
                                return ival2;
                            }
                            catch {
                                canDirect = false;
                            }
                        }

                        string val = t.GetValue <string>(att);

                        if (canDirect == null)
                        {
                            try {
                                ival2 = t.GetValue <int>(att);
                                return ival2;
                            }
                            catch {
                                canDirect = false;
                            }
                        }

                        if (!Int32.TryParse(val, out ival2))
                        {
                            if (val.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                            {
                                ival2 = FormatConverters.IntOrHexConverter(val);
                            }
                        }

                        return ival2;
                    }));
                }

                return(new Func <TValue, string, double>((t, s) => 0));
            }

            double ival;

            if (double.TryParse(Value.Replace(".", ","), out ival))
            {
                isInt = true;
            }
            else if (double.TryParse(Value.Replace(",", "."), out ival))
            {
                isInt = true;
            }
            else
            {
                if (Value.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                {
                    ival  = FormatConverters.IntOrHexConverter(Value);
                    isInt = true;
                }
            }

            return(new Func <TValue, string, double>((t, s) => ival));
        }
コード例 #22
0
        public ShopSimulatorDialog()
            : base("Shop simulator", "editor.png", SizeToContent.Height, ResizeMode.NoResize)
        {
            InitializeComponent();
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            Owner = WpfUtilities.TopWindow;

            _shopItems           = new RangeObservableCollection <ShopItem>();
            _lvItems.ItemsSource = _shopItems;

            Binder.Bind(_cbColorZeny, () => SdeAppConfiguration.UseZenyColors, () => _shopItems.ToList().ForEach(p => p.Update()));
            Binder.Bind(_cbDiscount, () => SdeAppConfiguration.UseDiscount, () => _shopItems.ToList().ForEach(p => p.Update()));
            Binder.Bind(_cbUseViewId, () => SdeAppConfiguration.AlwaysUseViewId, () => {
                if (!_enableEvents || _primaryShop == null)
                {
                    return;
                }

                try {
                    _enableEvents = false;

                    string viewId = _primaryShop.NpcViewId;
                    int ival;

                    if (SdeAppConfiguration.AlwaysUseViewId)
                    {
                        if (!Int32.TryParse(viewId, out ival))
                        {
                            var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants);
                            var tuple   = constDb.Table.TryGetTuple(viewId);

                            if (tuple != null)
                            {
                                ival = tuple.GetValue <int>(ServerConstantsAttributes.Value);
                            }
                            else
                            {
                                ival = -1;
                            }

                            _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture);
                            _tbNpcViewId.Text      = _primaryShop.NpcViewId;
                            _primaryShop.Reload();
                        }
                    }
                    else
                    {
                        if (Int32.TryParse(viewId, out ival))
                        {
                            viewId = _viewIdToString(ival);

                            if (!String.IsNullOrEmpty(viewId))
                            {
                                if (viewId.IsExtension(".act", ".spr"))
                                {
                                    _primaryShop.NpcViewId = Path.GetFileNameWithoutExtension(viewId.ToUpper());
                                }
                                else
                                {
                                    _primaryShop.NpcViewId = Path.GetFileName(viewId);
                                }

                                _tbNpcViewId.Text = _primaryShop.NpcViewId;
                                _primaryShop.Reload();
                            }
                        }
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
                finally {
                    _enableEvents = true;
                }
            });

            _shop.TextChanged += new EventHandler(_shop_TextChanged);

            AvalonLoader.Load(_shop);
            WpfUtils.AddMouseInOutEffectsBox(_cbColorZeny, _cbDiscount, _cbUseViewId);

            _helper = new PreviewHelper(new RangeListView(), SdeEditor.Instance.ProjectDatabase.GetDb <int>(ServerDbs.Items), null, null, null, null);

            FrameViewerSettings settings = new FrameViewerSettings();

            settings.Act            = () => _act;
            settings.SelectedAction = () => _actIndexSelected.SelectedAction;
            settings.SelectedFrame  = () => _actIndexSelected.SelectedFrame;
            _frameViewer.InitComponent(settings);

            _actIndexSelected.Init(_frameViewer);
            _actIndexSelected.Load(_act);
            _actIndexSelected.FrameChanged  += (s, p) => _frameViewer.Update();
            _actIndexSelected.ActionChanged += (s, p) => {
                _frameViewer.Update();

                if (!_enableEvents || _primaryShop == null)
                {
                    return;
                }

                try {
                    _enableEvents = false;

                    var elements = _tbNpcPosition.Text.Split(',');
                    var dir      = _convertAction(_actIndexSelected.SelectedAction);

                    if (elements.Length == 4)
                    {
                        elements[3] = dir.ToString(CultureInfo.InvariantCulture);
                        _primaryShop.ShopLocation = string.Join(",", elements);
                        _primaryShop.Reload();
                    }
                    else
                    {
                        _primaryShop.ShopLocation = "prontera,150,150," + dir.ToString(CultureInfo.InvariantCulture);
                        _primaryShop.Reload();
                    }

                    _tbNpcPosition.Text = _primaryShop.ShopLocation;
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
                finally {
                    _enableEvents = true;
                }
            };

            _actIndexSelected.SpecialFrameChanged += (s, p) => _frameViewer.Update();

            _lvItems.MouseRightButtonUp += new MouseButtonEventHandler(_lvItems_MouseRightButtonUp);
            _lvItems.SelectionChanged   += new SelectionChangedEventHandler(_lvItems_SelectionChanged);

            _tbItemId.TextChanged          += new TextChangedEventHandler(_tbItemId_TextChanged);
            _tbPrice.TextChanged           += new TextChangedEventHandler(_tbPrice_TextChanged);
            _tbNpcViewId.TextChanged       += new TextChangedEventHandler(_tbNpcViewId_TextChanged);
            _tbNpcPosition.TextChanged     += new TextChangedEventHandler(_tbNpcPosition_TextChanged);
            _tbNpcDisplayName.TextChanged  += new TextChangedEventHandler(_tbNpcDisplayName_TextChanged);
            _tbNpcShopCurrency.TextChanged += new TextChangedEventHandler(_tbNpcShopCurrency_TextChanged);

            _comboBoxShopType.SelectionChanged += new SelectionChangedEventHandler(_comboBoxShopType_SelectionChanged);

            _buttonResetPrice.Click += delegate {
                _tbPrice.Text = "-1";
            };

            _buttonCurItemQuery.Click += delegate {
                try {
                    Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

                    SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbNpcShopCurrency.Text);
                    select.Owner = WpfUtilities.TopWindow;

                    if (select.ShowDialog() == true)
                    {
                        _tbNpcShopCurrency.Text = select.Id;
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _buttonViewIdQuery.Click += delegate {
                try {
                    MultiGrfExplorer dialog = new MultiGrfExplorer(SdeEditor.Instance.ProjectDatabase.MetaGrf, "data\\sprite\\npc", "", _viewIdToString(FormatConverters.IntOrHexConverter(_primaryShop.NpcViewId ?? "")));

                    if (dialog.ShowDialog() == true)
                    {
                        var    path = dialog.SelectedPath.GetFullPath();
                        string result;

                        if (path.IsExtension(".act", ".spr"))
                        {
                            result = Path.GetFileNameWithoutExtension(path.ToUpper());
                        }
                        else
                        {
                            result = Path.GetFileName(path);
                        }

                        if (SdeAppConfiguration.AlwaysUseViewId)
                        {
                            var constDb = SdeEditor.Instance.ProjectDatabase.GetDb <string>(ServerDbs.Constants);
                            var tuple   = constDb.Table.TryGetTuple(result);
                            int ival;

                            if (tuple != null)
                            {
                                ival = tuple.GetValue <int>(ServerConstantsAttributes.Value);
                            }
                            else
                            {
                                _tbNpcViewId.Text = result;
                                return;
                            }

                            if (!_enableEvents || _primaryShop == null)
                            {
                                return;
                            }

                            try {
                                _enableEvents = false;

                                _primaryShop.NpcViewId = ival.ToString(CultureInfo.InvariantCulture);
                                _tbNpcViewId.Text      = _primaryShop.NpcViewId;
                                _updateViewShop();
                                _primaryShop.Reload();
                            }
                            catch (Exception err) {
                                ErrorHandler.HandleException(err);
                            }
                            finally {
                                _enableEvents = true;
                            }
                        }
                        else
                        {
                            _tbNpcViewId.Text = result;
                        }
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _buttonQueryItem.Click += delegate {
                try {
                    Table <int, ReadableTuple <int> > btable = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Items);

                    SelectFromDialog select = new SelectFromDialog(btable, ServerDbs.Items, _tbItemId.Text);
                    select.Owner = WpfUtilities.TopWindow;

                    if (select.ShowDialog() == true)
                    {
                        _tbItemId.Text = select.Id;
                    }
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            };

            _gridColumnPrimary.Width = new GridLength(230 + SystemParameters.VerticalScrollBarWidth + 7);

            this.Loaded += delegate {
                this.MinHeight  = this.ActualHeight + 10;
                this.MinWidth   = this.ActualWidth;
                this.ResizeMode = ResizeMode.CanResize;
                SizeToContent   = SizeToContent.Manual;
            };

            ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _buttonDelete_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.New, () => _buttonNew_Click(null, null), this);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Up", "MoveUp"), () => _buttonUp_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Down", "MoveDown"), () => _buttonDown_Click(null, null), _lvItems);
            ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _undo(), this);
            ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _redo(), this);
            //_shop.Text = "alberta_in,182,97,0	shop	Tool Dealer#alb2	73,1750:-1,611:-1,501:-1,502:-1,503:-1,504:-1,506:-1,645:-1,656:-1,601:-1,602:-1,2243:-1";
        }