예제 #1
0
        public static Mob Parse(WZProperty stringWz, bool followLink = true)
        {
            int id;

            if (!int.TryParse(stringWz.NameWithoutExtension, out id))
            {
                return(null);
            }

            Mob result = new Mob();

            result.Id = id;

            result.mobImage = stringWz.ResolveOutlink($"Mob/{id.ToString("D7")}") ?? stringWz.ResolveOutlink($"Mob2/{id.ToString("D7")}");

            result.Name    = stringWz.ResolveForOrNull <string>("name");
            result.Meta    = result.mobImage.Children.Any(c => c.NameWithoutExtension.Equals("info")) ? MobMeta.Parse(result.mobImage.Resolve("info")) : null;
            result.LinksTo = result.Meta.LinksToOtherMob;

            result.Framebooks = result.mobImage.Children
                                .Where(c => c.NameWithoutExtension != "info")
                                .DistinctBy(c => c.NameWithoutExtension)
                                .ToDictionary(c => c.NameWithoutExtension, c => FrameBook.GetFrameCount(c));

            WZProperty familiarEntry = stringWz.ResolveOutlink($"String/MonsterBook/{id}");

            result.Description = familiarEntry?.ResolveForOrNull <string>("episode");

            ILookup <int, MapName> lookup = MapName.GetMapNameLookup(stringWz);

            result.FoundAt = stringWz.ResolveOutlink($"Etc/MobLocation/{id}")?
                             .Children.Concat(familiarEntry?.Resolve("map")?.Children ?? (new Dictionary <string, WZProperty>()).Values)
                             .Select(c => c.ResolveFor <int>() ?? -1).Distinct()
                             .Select(c => lookup[c]?.FirstOrDefault() ?? new MapName()
            {
                Name = "Unknown", StreetName = "Unknown", Id = c
            })
                             .ToArray();

            ILookup <int, ItemNameInfo> reportedDrops = ItemNameInfo.GetNameLookup(stringWz.ResolveOutlink("String"));

            result.Drops = familiarEntry?.Resolve("reward")?.Children
                           .Select(c => c.ResolveFor <int>() ?? -1)
                           .Select(c => reportedDrops[c]?.FirstOrDefault())
                           .Where(c => c != null)
                           .ToArray();

            List <int> linkFollowed = new List <int>();
            Mob        linked       = result;

            while (followLink && linked.Meta.LinksToOtherMob.HasValue && !linkFollowed.Contains(linked.Meta.LinksToOtherMob.Value))
            {
                linkFollowed.Add(linked.Meta.LinksToOtherMob.Value);
                linked = Parse(stringWz.ResolveOutlink($"String/Mob/{linked.Meta.LinksToOtherMob.Value}"), false);
            }

            if (linked != result)
            {
                result.Extend(linked);
            }

            return(result);
        }
예제 #2
0
 private void Extend(Mob linked)
 {
     this.Framebooks = linked.Framebooks;
     this.mobImage   = linked.mobImage;
 }