Beispiel #1
0
        public static NPC Parse(WZProperty stringWz, bool followLink = true)
        {
            int id;

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

            NPC result = new NPC();

            result.Id = id;

            if (stringWz?.FileContainer?.Collection is MSPackageCollection)
            {
                ((MSPackageCollection)stringWz.FileContainer.Collection).NPCQuests?.TryGetValue(id, out result.RelatedQuests);
            }

            result.npcImg = stringWz.ResolveOutlink($"Npc/{id.ToString("D7")}");
            result.Link   = result.npcImg.ResolveFor <int>("info/link") ?? result.npcImg.ResolveFor <int>("link");
            List <int> linkFollowed = new List <int>();
            NPC        linked       = result;

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

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

            result.Function = stringWz.ResolveForOrNull <string>("func");
            result.Name     = stringWz.ResolveForOrNull <string>("name");
            result.Dialogue = stringWz.Children
                              .Where(c => c.NameWithoutExtension != "func" && c.NameWithoutExtension != "name" && c.NameWithoutExtension != "dialogue" && c is IWZPropertyVal)
                              .ToDictionary(c => c.NameWithoutExtension, c => ((IWZPropertyVal)c).GetValue().ToString());

            result.IsShop = result.npcImg?.ResolveFor <bool>("info/shop") ?? false;

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

            if (result.npcImg.Resolve("info/default")?.Type == PropertyType.Canvas)
            {
                result.Framebooks.Add("default", FrameBook.GetFrameCount(result.npcImg.Resolve("info/default")));
            }

            result.IsComponentNPC = result.npcImg.ResolveFor <bool>("info/componentNPC") ?? false;
            if (result.IsComponentNPC ?? false)
            {
                result.ComponentIds  = result.npcImg.Resolve("info/component")?.Children.Where(c => c.NameWithoutExtension != "skin").Select(c => c.ResolveFor <int>()).Where(c => c.HasValue).Select(c => c.Value).ToArray();
                result.ComponentSkin = result.npcImg.ResolveFor <int>("info/component/skin") + 2000;
            }

            result.FoundAt = result.npcImg.ResolveOutlink($"Etc/NpcLocation/{id}")?
                             .Children.Where(c => int.TryParse(c.NameWithoutExtension, out int blah))
                             .Select(c => MapName.GetMapNameLookup(result.npcImg)[int.Parse(c.NameWithoutExtension)].FirstOrDefault())
                             .Where(c => c != null).ToArray();

            return(result);
        }
Beispiel #2
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);
        }