Beispiel #1
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("}");
            }
        }
Beispiel #2
0
        public static string ToString <TValue>(int key)
        {
            var flagsData = FlagsManager.GetFlag <TValue>();

            if (flagsData != null)
            {
                return(flagsData.Value2Name[key]);
            }

            var dico = (Dictionary <TValue, string>)_dicosEnums2Strings[typeof(TValue)];

            return(_getValue(dico, (TValue)(object)key));
        }
        private string _findWeaponType(ReadableTuple <int> tupleSource)
        {
            var viewId  = _getInt(ServerItemAttributes.ClassNumber, tupleSource);
            var viewId2 = _getInt(ServerItemAttributes.SubType, tupleSource);

            if (viewId2 > 0)
            {
                var flagsData = FlagsManager.GetFlag <WeaponType>();
                var v         = flagsData.Values.FirstOrDefault(p => p.Value == viewId2);

                if (v != null)
                {
                    var index = flagsData.Values.IndexOf(v);
                    return(WeaponTypes[index]);
                }
            }

            if (viewId > 0 && viewId < WeaponTypes.Count)
            {
                return(WeaponTypes[viewId]);
            }

            return(null);
        }
Beispiel #4
0
        public static string LoadFlag <T>(ParserObject entry, string def = "")
        {
            if (entry == null)
            {
                return(def);
            }

            long flag     = 0;
            var  flagData = FlagsManager.GetFlag <T>();

            if (flagData == null)
            {
                throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag provided: " + typeof(T));
            }

            if (entry is ParserString)
            {
                long val;

                if (!flagData.Name2Value.TryGetValue(entry.ObjectValue, out val))
                {
                    FlagsManager.AddValue(flagData, entry.ObjectValue);
                }

                if (!flagData.Name2Value.TryGetValue(entry.ObjectValue, out val))
                {
                    throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + entry.ObjectValue);
                }

                return(flagData.Name2Value[entry.ObjectValue].ToString(CultureInfo.InvariantCulture));
            }

            foreach (var flagEntry in entry.OfType <ParserKeyValue>())
            {
                try {
                    long val = 0;

                    if (!flagData.Name2Value.TryGetValue(flagEntry.Key, out val))
                    {
                        FlagsManager.AddValue(flagData, flagEntry.Key);
                    }

                    if (!flagData.Name2Value.TryGetValue(flagEntry.Key, out val))
                    {
                        throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + flagEntry.Key);
                    }

                    if (flagEntry.Value == "true")
                    {
                        flag |= val;
                    }
                    else
                    {
                        flag &= ~val;
                    }
                }
                catch {
                    throw new FileParserException(TextFileHelper.LatestFile, entry.Line, "Unknown flag: " + flagEntry.Key);
                }
            }

            if (flag == 0 && def != "")
            {
                return(def);
            }

            return(flag.ToString(CultureInfo.InvariantCulture));
        }
Beispiel #5
0
        public static void WriteEntryYaml(StringBuilder builder, ReadableTuple <int> tuple, MetaTable <int> itemDb)
        {
            if (tuple != null)
            {
                int    value;
                bool   valueB;
                string valueS;

                builder.AppendLine("  - Id: " + tuple.GetKey <int>().ToString(CultureInfo.InvariantCulture));

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.Name)) != "")
                {
                    builder.AppendLine("    Name: " + DbIOUtils.QuoteCheck(valueS));
                }

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.Desc)) != "")
                {
                    builder.AppendLine("    Description: " + DbIOUtils.QuoteCheck(valueS));
                }

                builder.AppendLine("    MaxLevel: " + tuple.GetValue <int>(ServerSkillAttributes.MaxLevel));

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.AttackType)) != 0)
                {
                    builder.AppendLine("    Type: " + Constants.ToString <AttackTypeType>(value));
                }

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.SkillTargetType)) != 0)
                {
                    builder.AppendLine("    TargetType: " + Constants.ToString <SkillTargetType>(value));
                }

                DbIOUtils.ExpandFlag <SkillDamageType>(builder, tuple, "DamageFlags", ServerSkillAttributes.DamageFlags, YamlParser.Indent4, YamlParser.Indent6);
                DbIOUtils.ExpandFlag <SkillType2TypeNew>(builder, tuple, "Flags", ServerSkillAttributes.Inf2New, YamlParser.Indent4, YamlParser.Indent6);

                _expandList(builder, tuple, "Range", "      - Level", "Size", ServerSkillAttributes.Range, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.HitMode)) != 0)
                {
                    builder.AppendLine("    Hit: " + Constants.ToString <HitType>(value));
                }

                _expandList(builder, tuple, "HitCount", "      - Level", "Count", ServerSkillAttributes.HitCount, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "Element", "      - Level", "Element", ServerSkillAttributes.SkillElement, YamlParser.Indent4, YamlParser.Indent8, "Neutral", itemDb);
                _expandList(builder, tuple, "SplashArea", "      - Level", "Area", ServerSkillAttributes.SplashArea, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "ActiveInstance", "      - Level", "Max", ServerSkillAttributes.ActiveInstance, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "Knockback", "      - Level", "Amount", ServerSkillAttributes.Knockback, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);

                if (tuple.GetValue <int>(ServerSkillAttributes.CopyFlags) > 0 || tuple.GetValue <int>(ServerSkillAttributes.CopyFlagsRemovedRequirement) > 0)
                {
                    builder.AppendLine("    CopyFlags:");

                    DbIOUtils.ExpandFlag <SkillCopyType>(builder, tuple, "Skill", ServerSkillAttributes.CopyFlags, YamlParser.Indent6, YamlParser.Indent8);
                    DbIOUtils.ExpandFlag <SkillCopyRemoveRequirementType>(builder, tuple, "RemoveRequirement", ServerSkillAttributes.CopyFlagsRemovedRequirement, YamlParser.Indent6, YamlParser.Indent8);
                }

                if (tuple.GetValue <int>(ServerSkillAttributes.NoNearNPCRange) > 0 || tuple.GetValue <int>(ServerSkillAttributes.NoNearNPCType) > 0)
                {
                    builder.AppendLine("    NoNearNPC:");

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

                    DbIOUtils.ExpandFlag <NoNearNpcType>(builder, tuple, "Type", ServerSkillAttributes.NoNearNPCType, YamlParser.Indent6, YamlParser.Indent8);
                }

                if ((valueB = tuple.GetValue <bool>(ServerSkillAttributes.CastInterrupt)) != false)
                {
                    builder.AppendLine("    CastCancel: " + (valueB ? "true" : "false"));
                }

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

                _expandList(builder, tuple, "CastTime", "      - Level", "Time", ServerSkillAttributes.CastingTime, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "AfterCastActDelay", "      - Level", "Time", ServerSkillAttributes.AfterCastActDelay, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "AfterCastWalkDelay", "      - Level", "Time", ServerSkillAttributes.AfterCastWalkDelay, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "Duration1", "      - Level", "Time", ServerSkillAttributes.Duration1, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "Duration2", "      - Level", "Time", ServerSkillAttributes.Duration2, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "Cooldown", "      - Level", "Time", ServerSkillAttributes.Cooldown, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                _expandList(builder, tuple, "FixedCastTime", "      - Level", "Time", ServerSkillAttributes.FixedCastTime, YamlParser.Indent4, YamlParser.Indent8, "0", itemDb);
                DbIOUtils.ExpandFlag <CastingFlags>(builder, tuple, "CastTimeFlags", ServerSkillAttributes.CastTimeFlags, YamlParser.Indent4, YamlParser.Indent6);
                DbIOUtils.ExpandFlag <CastingFlags>(builder, tuple, "CastDelayFlags", ServerSkillAttributes.CastDelayFlags, YamlParser.Indent4, YamlParser.Indent6);

                StringBuilder require = new StringBuilder();
                _expandList(require, tuple, "HpCost", "        - Level", "Amount", ServerSkillAttributes.RequireHpCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "SpCost", "        - Level", "Amount", ServerSkillAttributes.RequireSpCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "HpRateCost", "        - Level", "Amount", ServerSkillAttributes.RequireHpRateCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "SpRateCost", "        - Level", "Amount", ServerSkillAttributes.RequireSpRateCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "MaxHpTrigger", "        - Level", "Amount", ServerSkillAttributes.RequireMaxHpTrigger, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "ZenyCost", "        - Level", "Amount", ServerSkillAttributes.RequireZenyCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);

                value = tuple.GetValue <int>(ServerSkillAttributes.RequireWeapons);

                if (value != 0xFFFFFF)
                {
                    DbIOUtils.ExpandFlag <WeaponType>(require, tuple, "Weapon", ServerSkillAttributes.RequireWeapons, YamlParser.Indent6, YamlParser.Indent8);
                }

                DbIOUtils.ExpandFlag <AmmoType>(require, tuple, "Ammo", ServerSkillAttributes.RequireAmmoTypes, YamlParser.Indent6, YamlParser.Indent8);
                _expandList(require, tuple, "AmmoAmount", "        - Level", "Amount", ServerSkillAttributes.RequireAmmoAmount, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.RequireState)) > 0)
                {
                    valueS = "";

                    switch ((RequiredStateTypeNew)value)
                    {
                    case RequiredStateTypeNew.Hidden:
                        valueS = "Hidden";
                        break;

                    case RequiredStateTypeNew.Riding:
                        valueS = "Riding";
                        break;

                    case RequiredStateTypeNew.Falcon:
                        valueS = "Falcon";
                        break;

                    case RequiredStateTypeNew.Cart:
                        valueS = "Cart";
                        break;

                    case RequiredStateTypeNew.Shield:
                        valueS = "Shield";
                        break;

                    case RequiredStateTypeNew.RecoverWeightRate:
                        valueS = "Recover_Weight_Rate";
                        break;

                    case RequiredStateTypeNew.MoveEnable:
                        valueS = "Move_Enable";
                        break;

                    case RequiredStateTypeNew.Water:
                        valueS = "Water";
                        break;

                    case RequiredStateTypeNew.RidingDragon:
                        valueS = "Ridingdragon";
                        break;

                    case RequiredStateTypeNew.Warg:
                        valueS = "Wug";
                        break;

                    case RequiredStateTypeNew.Ridingwarg:
                        valueS = "Ridingwug";
                        break;

                    case RequiredStateTypeNew.Mado:
                        valueS = "Mado";
                        break;

                    case RequiredStateTypeNew.Elementalspirit:
                        valueS = "Elementalspirit";
                        break;

                    case RequiredStateTypeNew.Elementalspirit2:
                        valueS = "Elementalspirit2";
                        break;

                    case RequiredStateTypeNew.RidingPeco:
                        valueS = "Peco";
                        break;

                    case RequiredStateTypeNew.SunStance:
                        valueS = "Sunstance";
                        break;

                    case RequiredStateTypeNew.MoonStance:
                        valueS = "Moonstance";
                        break;

                    case RequiredStateTypeNew.StarsStance:
                        valueS = "Starstance";
                        break;

                    case RequiredStateTypeNew.UniverseStance:
                        valueS = "Universestance";
                        break;

                    default:
                        valueS = "";
                        break;
                    }

                    require.Append("      State: ");
                    require.AppendLine(valueS);
                }

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.RequireStatuses)) != "" && valueS != "0")
                {
                    var data = valueS.Split(':');

                    if (data.Length > 0)
                    {
                        require.AppendLine("      Status:");

                        foreach (var da in data)
                        {
                            require.Append("        ");
                            require.Append(da);
                            require.AppendLine(": true");
                        }
                    }
                }

                //_DbIOUtils.ExpandFlag<AmmoType>(require, tuple, "Status", ServerSkillAttributes.RequireStatuses, YamlParser2.Indent6, YamlParser2.Indent8);
                _expandList(require, tuple, "SpiritSphereCost", "        - Level", "Amount", ServerSkillAttributes.RequireSpiritSphereCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(require, tuple, "ItemCost", "        - Item", "Amount", ServerSkillAttributes.RequireItemCost, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.RequiredEquipment)) != "" && valueS != "0")
                {
                    var data = valueS.Split(':');

                    require.AppendLine("      Equipment:");

                    foreach (var item in data)
                    {
                        require.Append("        ");
                        require.Append(DbIOUtils.Id2Name(itemDb, ServerItemAttributes.AegisName, item));
                        require.AppendLine(": true");
                    }
                }
                //_expandList(require, tuple, "Equipment", "", "", ServerSkillAttributes.RequiredEquipment, YamlParser2.Indent6, YamlParser2.Indent8, "", itemDb);

                string requireData = require.ToString();

                if (requireData != "")
                {
                    builder.AppendLine("    Requires:");
                    builder.Append(requireData);
                }

                StringBuilder unit = new StringBuilder();

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.UnitId)) != "" && valueS != "0")
                {
                    unit.Append("      Id: ");
                    unit.AppendLine(valueS);
                }

                if ((valueS = tuple.GetValue <string>(ServerSkillAttributes.UnitAlternateId)) != "" && valueS != "0")
                {
                    unit.Append("      AlternateId: ");
                    unit.AppendLine(valueS);
                }

                _expandList(unit, tuple, "Layout", "        - Level", "Size", ServerSkillAttributes.UnitLayout, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);
                _expandList(unit, tuple, "Range", "        - Level", "Size", ServerSkillAttributes.UnitRange, YamlParser.Indent6, YamlParser.Indent10, "0", itemDb);

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.UnitInterval)) != 0)
                {
                    unit.Append("      Interval: ");
                    unit.AppendLine(value.ToString(CultureInfo.InvariantCulture));
                }

                if ((value = tuple.GetValue <int>(ServerSkillAttributes.UnitTarget)) != 0x3F0000)
                {
                    unit.Append("      Target: ");

                    var flag = FlagsManager.GetFlag <UnitTargetType>();
                    valueS = flag.Value2Name[value];
                    unit.AppendLine(valueS);
                }

                DbIOUtils.ExpandFlag <UnitFlagType>(unit, tuple, "Flag", ServerSkillAttributes.UnitFlag, YamlParser.Indent6, YamlParser.Indent8);

                string unitData = unit.ToString();

                if (unitData != "")
                {
                    builder.AppendLine("    Unit:");
                    builder.Append(unit);
                }
            }
        }