Ejemplo n.º 1
0
        public static void ResolveItemRef(BdatStringValue value)
        {
            if (value.Resolved)
            {
                return;
            }

            BdatStringItem       item   = value.Parent;
            BdatStringTable      table  = item.Table;
            BdatStringCollection tables = table.Collection;
            BdatMember           member = value.Member;
            BdatFieldInfo        field  = member.Metadata;

            if (value.Array != null)
            {
                foreach (var element in value.Array)
                {
                    ResolveItemRef(element);
                }

                value.Resolved = true;
                return;
            }

            if (field == null)
            {
                value.Resolved = true;
                return;
            }

            int refId = int.Parse(value.ValueString) + field.Adjust;

            switch (field.Type)
            {
            case BdatFieldType.Message:
                value.Display = tables[field.RefTable][refId]?["name"].DisplayString;
                if (string.IsNullOrWhiteSpace(value.DisplayString) && refId > 0)
                {
                    value.Display = refId.ToString();
                }
                break;

            case BdatFieldType.Reference:
                ApplyRef(field.RefTable);
                break;

            case BdatFieldType.Item:
                if (tables.Game == Game.XB2)
                {
                    ApplyRef(BdatStringTools.GetItemTableXb2(refId));
                }
                if (tables.Game == Game.XB1)
                {
                    var itemType = (ItemTypeXb1)int.Parse(item[field.RefField].ValueString);
                    ApplyRef(BdatStringTools.GetItemTableXb1(itemType));
                }
                if (tables.Game == Game.XBX)
                {
                    var itemType = (ItemTypeXbx)int.Parse(item[field.RefField].ValueString);
                    ApplyRef(BdatStringTools.GetItemTableXbx(itemType));
                }

                break;

            case BdatFieldType.Event:
                ApplyRef(BdatStringTools.GetEventTable(refId));
                break;

            case BdatFieldType.EventSetup:
                ApplyRef(BdatStringTools.GetEventSetupTable(refId));
                break;

            case BdatFieldType.QuestFlag:
                ApplyRef(BdatStringTools.GetQuestListTable(refId));
                break;

            case BdatFieldType.QuestFlagIra:
                ApplyRef(BdatStringTools.GetQuestListIraTable(refId));
                break;

            case BdatFieldType.Condition:
                var conditionType = (ConditionType)int.Parse(item[field.RefField].ValueString);
                ApplyRef(BdatStringTools.GetConditionTable(conditionType));
                break;

            case BdatFieldType.Task:
                var taskType = (TaskType)int.Parse(item[field.RefField].ValueString);
                ApplyRef(BdatStringTools.GetTaskTable(taskType));
                break;

            case BdatFieldType.ShopTable:
                var shopType = (ShopType)int.Parse(item[field.RefField].ValueString);
                ApplyRef(BdatStringTools.GetShopTable(shopType));
                break;

            case BdatFieldType.Character:
                ApplyRef(BdatStringTools.GetCharacterTable(refId));
                break;

            case BdatFieldType.Enhance:
                value.Display = BdatStringTools.GetEnhanceCaption(value);
                break;

            case BdatFieldType.WeatherIdMap:
                value.Display = BdatStringTools.PrintWeatherIdMap(refId, 13, tables);
                break;

            case BdatFieldType.PouchBuff:
                value.Display = GetPouchBuffCaption(value);
                break;

            case BdatFieldType.Flag:
                AddFlag(tables, field.RefTable, refId, value);
                break;

            case BdatFieldType.GameFlag:
                var flagType = item[field.RefField].ValueString;
                AddFlag(tables, flagType + "bit", refId, value);
                break;

            case BdatFieldType.Change:
                var changeType = (ChangeType)int.Parse(item[field.RefField].ValueString);
                if (changeType == ChangeType.scenario)
                {
                    AddFlag(tables, "Scenario", refId, value);
                }
                break;

            case BdatFieldType.ItemComment:
                ApplyRef(item.Id >= 1852 ? "MNU_item_mes_b" : "MNU_item_mes_a");
                break;

            case BdatFieldType.Layer:
                ApplyRef(BdatStringTools.GetLayerTable(refId));
                break;

            case BdatFieldType.Place:
                var placeCat = (PlaceCategory)int.Parse(item[field.RefField].ValueString);
                ApplyRef(BdatStringTools.GetPlaceTable(placeCat, refId));
                break;
            }

            if (field.EnumType != null)
            {
                if (field.EnumType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0)
                {
                    value.Display = BdatStringTools.PrintEnumFlags(field.EnumType, refId);
                }
                else
                {
                    value.Display = Enum.GetName(field.EnumType, refId);
                }
            }

            value.Resolved = true;

            void ApplyRef(string refTable)
            {
                if (refTable == null || !tables.Tables.ContainsKey(refTable) || !tables[refTable].ContainsId(refId))
                {
                    value.Display = refId == 0 ? null : refId.ToString();
                    return;
                }

                var reft = tables[refTable][refId].Display;

                if (reft != null)
                {
                    if (!reft.Resolved)
                    {
                        ResolveItemRef(reft);
                    }

                    if (!string.IsNullOrWhiteSpace(reft.DisplayString))
                    {
                        value.Display = reft.Display;
                    }
                }

                value.Reference = tables[refTable][refId];
                tables[refTable][refId].ReferencedBy.Add(value.Parent);
            }
        }