Example #1
0
        // TODO: Flesh out set effect attributes
        // activeSkill + EquipInfo + Others?
        //public Dictionary<int, > Effects;

        public static ItemSet ParseItemInfo(WZProperty info)
        {
            if (!info.Children.Any(c => c.NameWithoutExtension.Equals("setItemID")))
            {
                return(null);
            }

            return(Parse(info.ResolveOutlink(Path.Combine("Etc", "SetItemInfo", (info.ResolveFor <int>("setItemID") ?? -1).ToString()))));
        }
Example #2
0
        public static Equip Parse(WZProperty itemString)
        {
            string group = itemString.Parent.NameWithoutExtension;
            int    id    = int.Parse(itemString.NameWithoutExtension);
            Equip  item  = new Equip(id, group);

            try
            {
                WZProperty characterItem = itemString.ResolveOutlink(Path.Combine("Character", group, $"{id.ToString("D8")}.img"));
                item.MetaInfo    = ItemInfo.Parse(characterItem);
                item.Description = ItemDescription.Parse(itemString, id);

                bool hasEffectsPerItemType = characterItem.Children.Where(c => c.NameWithoutExtension != "info").All(c => int.TryParse(c.NameWithoutExtension, out int blah));

                if (hasEffectsPerItemType)
                {
                    item.FrameBooksPerWeaponType = characterItem.Children.Where(c => c.NameWithoutExtension != "info")
                                                   .ToDictionary(c => int.Parse(c.NameWithoutExtension), c => ProcessFrameBooks(c));
                    item.FrameBooks = item.FrameBooksPerWeaponType.Values.FirstOrDefault() ?? new Dictionary <string, EquipFrameBook>();
                }
                else
                {
                    item.FrameBooks = ProcessFrameBooks(characterItem);
                }

                WZProperty effect = itemString.ResolveOutlink($"Effect/ItemEff/{id}");
                if (effect != null)
                {
                    item.ItemEffects = Effects.Parse(effect);
                }

                return(item);
            }
            catch (Exception ex)
            {
                ErrorCallback($"{ex.Message}{Environment.NewLine}{ex.StackTrace}");
                return(null);
            }
        }
Example #3
0
        public static ILookup <int, MapName> GetMapNameLookup(WZProperty anyWz)
        {
            ILookup <int, MapName> lookup = null;

            if (anyWz.FileContainer.Collection.VersionCache.TryGetValue("mapNames", out object mapNamesCached))
            {
                lookup = (ILookup <int, MapName>)mapNamesCached;
            }
            else
            {
                lookup = anyWz.ResolveOutlink("String/Map").Children.SelectMany(c => c.Children).ToLookup(c => int.Parse(c.NameWithoutExtension), c => MapName.Parse(c));
                anyWz.FileContainer.Collection.VersionCache.AddOrUpdate("mapNameLookup", lookup, (a, b) => b);
            }

            return(lookup);
        }
Example #4
0
        public static Special Parse(WZProperty stringWz)
        {
            int id;

            if (!int.TryParse(stringWz.NameWithoutExtension, out id))
            {
                return(null);
            }
            Special    item      = new Special(id);
            WZProperty specialWz = stringWz.ResolveOutlink($"Item/Special/{id.ToString("D8").Substring(0, 4)}.img/{id.ToString("D8")}");

            item.MetaInfo    = ItemInfo.Parse(specialWz);
            item.Description = ItemDescription.Parse(stringWz, id);

            return(item);
        }
Example #5
0
        public static Frame GetFirstFrame(WZProperty anyWz, string id)
        {
            WZProperty npcImg = anyWz.ResolveOutlink($"Npc/{id}");

            if (npcImg == null)
            {
                return(null);
            }
            string linksTo = npcImg.ResolveForOrNull <string>("info/link");

            if (linksTo != null)
            {
                return(GetFirstFrame(anyWz, linksTo));
            }
            return(FrameBook.Parse(npcImg.Children.Where(c => c.NameWithoutExtension != "info").Select(c => c).FirstOrDefault())
                   .FirstOrDefault().frames.FirstOrDefault());
        }
Example #6
0
        public static Pet Parse(WZProperty stringWz)
        {
            int id;

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

            Pet        p        = new Pet(id);
            WZProperty petEntry = stringWz.ResolveOutlink($"Item/Pet/{id}");

            p.frameBooks  = petEntry.Children.Where(c => c.NameWithoutExtension != "info").ToDictionary(c => c.NameWithoutExtension, c => FrameBook.Parse(c));
            p.Description = ItemDescription.Parse(stringWz, id);
            p.MetaInfo    = ItemInfo.Parse(petEntry);

            return(p ?? null);
        }
        public static MapBackground Parse(WZProperty data)
        {
            MapBackground result = new MapBackground();

            result.BackgroundSet = data.ResolveForOrNull <string>("bS");
            result.pathToImage   = string.Join("/", new [] {
                result.BackgroundSet, // backgroundSet,
                "back",
                data.ResolveForOrNull <string>("no")
            });
            result.Index = int.Parse(data.Name);
            result.Front = data.ResolveFor <bool>("front") ?? false;
            result.Alpha = (data.ResolveFor <int>("a") ?? 255) / 255;
            result.Flip  = data.ResolveFor <bool>("f") ?? false;
            WZProperty tileCanvas = data.ResolveOutlink($"Map/Back/{result.pathToImage}") ?? data.ResolveOutlink($"Map2/Back/{result.pathToImage}") ?? data.ResolveOutlink($"Map001/Back/{result.pathToImage}");

            if (tileCanvas != null) // Could be null as we're not supporting ani backgrounds
            {
                result.Canvas = Frame.Parse(tileCanvas?.Children.FirstOrDefault(c => c.Type == PropertyType.Canvas) ?? tileCanvas);
            }
            else
            {
                return(null);
            }
            if (result.Canvas.Image == null)
            {
                return(null);
            }
            if (result.Flip && result.Canvas != null && result.Canvas.Image != null)
            {
                result.Canvas.Image = result.Canvas.Image.Clone(c => c.Flip(FlipMode.Horizontal));
            }
            result.Type     = (BackgroundType)(data.ResolveFor <int>("type") ?? 0);
            result.Position = new Vector3(
                data.ResolveFor <int>("x") ?? 0,
                data.ResolveFor <int>("y") ?? 0,
                result.Front ? 100000000 : int.Parse(data.NameWithoutExtension)
                );
            result.rx = data.ResolveFor <int>("rx") ?? 0;
            result.ry = data.ResolveFor <int>("ry") ?? 0;
            result.cx = data.ResolveFor <int>("cx") ?? 0;
            result.cy = data.ResolveFor <int>("cy") ?? 0;
            return(result);
        }
Example #8
0
        public static Consume Parse(WZProperty stringWz)
        {
            int id;

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

            Consume item = new Consume(id);

            WZProperty itemWz = stringWz.ResolveOutlink($"Item/Consume/{id.ToString("D8").Substring(0, 4)}.img/{id.ToString("D8")}");

            if (itemWz.Children.Any(c => c.NameWithoutExtension.Equals("info")))
            {
                item.MetaInfo = ItemInfo.Parse(itemWz);
            }
            item.Description = ItemDescription.Parse(stringWz, id);

            return(item);
        }
Example #9
0
        public static ItemSet Parse(WZProperty set)
        {
            ItemSet result = new ItemSet();
            ILookup <int, ItemNameInfo> itemNameLookup = ItemNameInfo.GetNameLookup(set.ResolveOutlink("String"));

            result.SetName       = set.ResolveForOrNull <string>("setItemName");
            result.CompleteCount = set.ResolveFor <int>("completeCount") ?? 1;
            result.RequiredItems = set.Resolve("ItemID").Children.Select(c =>
            {
                if (c.Type == PropertyType.SubProperty)
                {
                    return(c.Children.Where(b => int.TryParse(b.NameWithoutExtension, out int blah)).Select(b => b.ResolveFor <int>() ?? -1));
                }
                else
                {
                    return new int[] { c.ResolveFor <int>() ?? -1 }
                };
            }).Select(c => c.Select(b => itemNameLookup[b].First()));

            return(result);
        }
Example #10
0
        public static MapObject Parse(WZProperty data, int frame)
        {
            MapObject result = new MapObject();

            result.pathToImage = string.Join("/", (new [] {
                data.ResolveForOrNull <string>("oS"),
                data.ResolveForOrNull <string>("l0"),
                data.ResolveForOrNull <string>("l1"),
                data.ResolveForOrNull <string>("l2"),
            }).Where(c => c != null));
            result.FrontMost = data.ResolveFor <bool>("front") ?? false;
            result.Position  = new Vector3(
                data.ResolveFor <float>("x") ?? 0,
                data.ResolveFor <float>("y") ?? 0,
                result.FrontMost ? 100000000 : data.ResolveFor <float>("z") ?? 0
                );
            result.SecondZ = data.ResolveFor <float>("zM") ?? 0;
            result.Quests  = data.Resolve("quest")?.Children?
                             .Where(c => int.TryParse(c.NameWithoutExtension, out int blah))
                             .Select(c => int.Parse(c.NameWithoutExtension))
                             .ToArray();
            result.Tags     = data.ResolveForOrNull <string>("tags");
            result.Rotation = data.ResolveFor <float>("r");
            WZProperty objCanvas = data.ResolveOutlink($"Map/Obj/{result.pathToImage}") ?? data.ResolveOutlink($"Map2/Obj/{result.pathToImage}");

            if (objCanvas == null)
            {
                return(null);
            }
            int frameCount = objCanvas.Resolve().Children.Select(c => int.TryParse(c.NameWithoutExtension, out int frameNum) ? (int?)frameNum : null).Where(c => c.HasValue).Select(c => c.Value).Max();

            result.Canvas = Frame.Parse(objCanvas.Resolve((frame % (frameCount + 1)).ToString()) ?? objCanvas);
            result.Flip   = data.ResolveFor <bool>("f") ?? false;
            if (result.Flip && result.Canvas != null && result.Canvas.Image != null)
            {
                result.Canvas.Image = result.Canvas.Image.Clone(c => c.Flip(FlipMode.Horizontal));
            }

            return(result);
        }
Example #11
0
        public static Cash Parse(WZProperty stringWz)
        {
            int id;

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

            Cash item = new Cash(id);

            WZProperty itemWz = stringWz.ResolveOutlink($"Item/Cash/{id.ToString("D8").Substring(0, 4)}.img/{id.ToString("D8")}");

            if (itemWz != null)
            {
                item.MetaInfo = ItemInfo.Parse(itemWz);
                item.effect   = CashEffect.Parse((itemWz?.Resolve("effect") ?? itemWz));
            }
            item.Description = ItemDescription.Parse(stringWz, id);

            return(item);
        }
Example #12
0
        public static Install Parse(WZProperty stringWz)
        {
            int id;

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

            Install item = new Install(id);

            string     itemIdStr = id.ToString("D8");
            WZProperty itemWz    = stringWz.ResolveOutlink($"Item/Install").Children.FirstOrDefault(b => itemIdStr.StartsWith(b.NameWithoutExtension)).Resolve(itemIdStr);

            if (itemWz.Children.Any(c => c.NameWithoutExtension.Equals("info")))
            {
                item.MetaInfo = ItemInfo.Parse(itemWz);
            }
            item.Description = ItemDescription.Parse(stringWz, id);

            return(item);
        }
Example #13
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);
        }
Example #14
0
 public static MobInfo GetFromId(WZProperty anyWz, int mobId)
 => Parse(anyWz.ResolveOutlink($"String/Mob/{mobId}"));
Example #15
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);
        }