Beispiel #1
0
        // ToDo: я не уверен что тут тип меты такой - надо протестить (аналогично везде, в загрузке из json-а и тд)
        public void LoadMeta(WhJsonMeta meta)
        {
            Models = new WhItemModel[5];

            for (int i = 0; i < Models.Length; i++)
            {
                // ToDo: не факт что это правильно так как там jtoken (возможно он вообще null не может быть тут),
                // надо узнать какой вариант сериализации тут (там 2 возможных вариант, массив строк и массив объектов)
                // пока сделал через список строк, так как массив строк также используется где-то там где itemvisual хэндлит загрузку mo3
                if (meta.GetEquipmentAsStringIds()[i] != null)
                {
                    Models[i] = new WhItemModel
                    {
                        Race       = WhRace.Undefined2,
                        Gender     = WhGender.MALE,
                        Bone       = -1,
                        Attachment = null,
                        Model      = null
                    };

                    var modelInfo = new WhModelInfo
                    {
                        Type   = WhType.ITEMVISUAL,
                        Id     = Id.ToString(),
                        Parent = Model
                    };

                    Models[i].Model = new WhModel(Model.Opts, modelInfo, i);
                }
            }

            Loaded = true;
            Model.UpdateMeshes();
        }
        private uint SelectBestTexture(WhJsonMeta meta, string textureid, WhGender gender, WhClass cls, WhRace race)
        {
            var textures = meta.TextureFiles[textureid];

            for (int i = 0; i < textures.Length; i++)
            {
                var texture = textures[i];
                if (texture.Race != 0 && texture.Race == race && (texture.Class != 0 && texture.Class == cls) && (texture.Gender == gender || texture.Gender == WhGender.Undefined3))
                {
                    return(texture.FileDataId);
                }
            }

            for (int i = 0; i < textures.Length; i++)
            {
                var texture = textures[i];
                if (texture.Race != 0 && texture.Race == race && (texture.Gender == gender || texture.Gender == WhGender.Undefined3))
                {
                    return(texture.FileDataId);
                }
            }

            for (int i = 0; i < textures.Length; i++)
            {
                var texture = textures[i];
                if (texture.Class != 0 && texture.Class == cls && (texture.Gender == gender || texture.Gender == WhGender.Undefined3))
                {
                    return(texture.FileDataId);
                }
            }

            for (int i = 0; i < textures.Length; i++)
            {
                var texture = textures[i];
                if (texture.Gender == gender || texture.Gender == WhGender.Undefined3)
                {
                    return(texture.FileDataId);
                }
            }

            throw new System.NotImplementedException("selectBestTexture for " + textureid + ", gender " + gender + ", class " + cls + ", race " + race + " failed!");
        }
        public void LoadMeta(WhJsonMeta meta)
        {
            Flags        = meta.Item.Flags;
            Slot         = meta.Item.InventoryType;
            ItemClass    = meta.Item.ItemClass;
            ItemSubClass = meta.Item.ItemSubClass;

            if (meta.ComponentTextures != null)
            {
                Textures = new List <WhItemTexture>();
                foreach (var componentTexture in meta.ComponentTextures)
                {
                    var region  = componentTexture.Key;
                    var texFile = SelectBestTexture(meta, componentTexture.Value, Model.Gender, Model.Class, Model.Race);

                    WhItemTexture texture = null;
                    if (texFile != 0)
                    {
                        texture = new WhItemTexture()
                        {
                            Region  = region,
                            Gender  = Model.Gender,
                            File    = texFile,
                            Texture = null
                        };

                        if (region != WhRegion.Base)
                        {
                            texture.Texture = new WhTexture(Model, (int)region, texFile);
                        }
                        else if (Slot == WhSlot.CAPE)
                        {
                            Model.TextureOverrides[2] = new WhTexture(Model, 2, texFile);
                        }
                    }

                    Textures.Add(texture);
                }
            }

            GeosetGroup = meta.Item.GeosetGroup;
            if (Slot == WhSlot.HEAD)
            {
                var gender     = Model.Gender;
                var hideGeoset = gender == WhGender.MALE ? meta.Item.HideGeosetMale : meta.Item.HideGeosetFemale;
                if (gender == WhGender.MALE)
                {
                    HideGeosetMale = meta.Item.HideGeosetMale;
                }
                else
                {
                    HideGeosetFemale = meta.Item.HideGeosetFemale;
                }
            }

            if (Slot == WhSlot.SHOULDER)
            {
                Models = new List <WhItemModel>()
                {
                    null, null
                }
            }
            ;
            else if (WhGlobal.SlotType[Slot] != WhType.ARMOR)
            {
                Models = new List <WhItemModel>()
                {
                    null
                }
            }
            ;

            if (Models != null)
            {
                for (int i = 0; i < Models.Count; i++)
                {
                    var model = new WhItemModel()
                    {
                        Race       = Race,
                        Gender     = Gender,
                        Bone       = -1,
                        Attachment = null,
                        Model      = null
                    };

                    var modelInfo = new WhModelInfo()
                    {
                        Type   = WhGlobal.SlotType[Slot],
                        Id     = Id.ToString(),
                        Parent = Model
                    };

                    if (Slot == WhSlot.SHOULDER)
                    {
                        modelInfo.Shoulder = i + 1;
                    }

                    model.Model = new WhModel(Model.Opts, modelInfo, i, true);
                    model.Model.LoadMeta(meta, modelInfo.Type);
                    Models[i] = model;
                }
            }

            if (Slot == WhSlot.BELT && meta.Model != 0)
            {
                var model = new WhItemModel()
                {
                    Race       = WhRace.Undefined2,
                    Gender     = WhGender.MALE,
                    Bone       = -1,
                    Attachment = null,
                    Model      = null
                };

                var modelInfo = new WhModelInfo()
                {
                    Type   = WhGlobal.SlotType[Slot],
                    Id     = Id.ToString(),
                    Parent = Model
                };

                model.Model = new WhModel(Model.Opts, modelInfo, 0, true);
                model.Model.LoadMeta(meta, WhType.ARMOR);
                Models = new List <WhItemModel>()
                {
                    model
                };
            }

            if (Slot == WhSlot.SHIRT || Slot == WhSlot.CHEST || Slot == WhSlot.ROBE || Slot == WhSlot.BELT || Slot == WhSlot.PANTS || Slot == WhSlot.HANDS || Slot == WhSlot.BOOTS || Slot == WhSlot.HEAD)
            {
                int componentIndex = 0;
                if (Slot == WhSlot.HEAD)
                {
                    componentIndex = 1;
                }

                if (meta.ComponentModels != null && meta.ComponentModels.ContainsKey(componentIndex.ToString()))
                {
                    var modelId = meta.ComponentModels[componentIndex.ToString()];

                    if (modelId != 0 && meta.ModelFiles.ContainsKey(modelId))
                    {
                        var modelInfo = new WhModelInfo()
                        {
                            Type   = WhGlobal.SlotType[Slot],
                            Id     = Id.ToString(),
                            Parent = Model
                        };

                        var model = new WhModel(Model.Opts, modelInfo, 0, true);

                        model.Meta    = meta;
                        model.IsDirty = true;

                        var race   = WhRace.HUMAN;
                        var gender = WhGender.MALE;
                        var cls    = WhClass.WARRIOR;

                        if (Model != null)
                        {
                            race   = Model.Race;
                            gender = Model.Gender;
                            cls    = Model.Class;
                        }

                        var modelFile = model.SelectBestModel(modelId, gender, cls, race);
                        if (modelFile != 0)
                        {
                            if (Model != null)
                            {
                                if (!Model.CollectionModels.ContainsKey(modelFile))
                                {
                                    Model.CollectionModels[modelFile] = model;
                                    CollectionModel = model;
                                    model._Load(WhType.PATH, modelFile.ToString());
                                }
                                else
                                {
                                    CollectionModel = Model.CollectionModels[modelFile];
                                }
                            }
                            else
                            {
                                model._Load(WhType.PATH, modelFile.ToString());
                            }

                            if (meta.Textures != null)
                            {
                                foreach (var texturePair in meta.Textures)
                                {
                                    model.TextureOverrides[texturePair.Key] = new WhTexture(model, texturePair.Key, texturePair.Value);
                                }
                            }
                        }
                    }
                }
            }

            if (Slot == WhSlot.PANTS && GeosetGroup[2] > 0)
            {
                SortValue += 2;
            }

            if (Visualid != 0)
            {
                Visual = new WhItemVisual(Models[0].Model, Visualid);
            }

            Loaded = true;

            Model.UpdateMeshes();
        }