예제 #1
0
        public static Item Load(Models.GameObject obj, GomObject gom)
        {
            var itm = (Models.Item)obj;

            itm.NodeId          = gom.Id;
            itm.Fqn             = gom.Name;
            itm.AppearanceColor = Models.AppearanceColorExtensions.ToAppearanceColor((string)gom.Data.ValueOrDefault <string>("itmEnhancementColor", null));
            itm.ArmorSpec       = Models.ArmorSpecExtensions.ToArmorSpec((long)gom.Data.ValueOrDefault <long>("itmArmorSpec", 0));
            itm.Binding         = Models.ItemBindingRuleExtensions.ToBindingRule((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmBindingRule", null));

            itm.CombinedStatModifiers = new ItemStatList();
            itm.ConsumedOnUse         = (bool)gom.Data.ValueOrDefault <bool>("itmConsumedOnUse", false);
            //itm.Conversation
            itm.ConversationFqn = gom.Data.ValueOrDefault <string>("itmConversation", null);

            var descLookup = (GomObjectData)(gom.Data.Get <Dictionary <object, object> >("locTextRetrieverMap")[DescLookupKey]);

            itm.DescriptionId = descLookup.Get <long>("strLocalizedTextRetrieverStringID");
            itm.Description   = StringTable.TryGetString(itm.Fqn, descLookup);

            itm.DisassembleCategory    = Models.ProfessionSubtypeExtensions.ToProfessionSubtype((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("prfDisassembleCategory", null));
            itm.Durability             = (int)gom.Data.ValueOrDefault <long>("itmMaxDurability", 0);
            itm.EnhancementCategory    = Models.EnhancementCategoryExtensions.ToEnhancementCategory((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmEnhancementCategory", null));
            itm.EnhancementSubCategory = Models.EnhancementSubCategoryExtensions.ToEnhancementSubCategory((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmEnhancementSubCategory", null));
            itm.EnhancementType        = Models.EnhancementTypeExtensions.ToEnhancementType((long)gom.Data.ValueOrDefault <long>("itmEnhancementType", 0));

            // Enhancement Slots
            itm.EnhancementSlots = new ItemEnhancementList();
            var enhancementSlots    = (List <object>)gom.Data.ValueOrDefault <List <object> >("itmEnhancementSlots", null);
            var enhancementDefaults = (List <object>)gom.Data.ValueOrDefault <List <object> >("itmEnhancementDefaults", null);

            if (enhancementSlots != null)
            {
                for (var i = 0; i < 5; i++)
                {
                    long slot = (long)enhancementSlots[i];
                    if (slot == 0)
                    {
                        continue;
                    }

                    ItemEnhancement enh = new ItemEnhancement();
                    enh.Slot           = EnhancementTypeExtensions.ToEnhancementType(slot);
                    enh.ModificationId = (ulong)enhancementDefaults[i];
                    if (enh.ModificationId != 0)
                    {
                        enh.Modification = ItemLoader.Load(enh.ModificationId);
                    }

                    // Don't add empty modulator/augment slots to gear since for some reason it seems to be on every damn modifiable item
                    if ((enh.Slot == EnhancementType.Modulator) && (enh.Modification == null))
                    {
                        continue;
                    }

                    itm.EnhancementSlots.Add(enh);
                }
            }

            itm.EquipAbilityId = gom.Data.ValueOrDefault <ulong>("itmEquipAbility", 0);
            itm.EquipAbility   = AbilityLoader.Load(itm.EquipAbilityId);

            itm.GiftRank = Models.GiftRankExtensions.ToGiftRank((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmGiftAffectionRank", null));
            itm.GiftType = Models.GiftTypeExtensions.ToGiftType((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmGiftType", null));
            itm.Icon     = gom.Data.ValueOrDefault <string>("itmIcon", String.Empty);
            TorLib.Icons.Add(itm.Icon);

            itm.ItemLevel    = (int)gom.Data.ValueOrDefault <long>("itmBaseLevel", 0);
            itm.MaxStack     = (int)gom.Data.ValueOrDefault <long>("itmStackMax", 0);
            itm.ModifierSpec = gom.Data.ValueOrDefault <long>("itmModifierSetID", 0);
            itm.MountSpec    = gom.Data.ValueOrDefault <long>("itmMountSpec", 0);

            var nameLookup = (GomObjectData)(gom.Data.Get <Dictionary <object, object> >("locTextRetrieverMap")[NameLookupKey]);

            itm.NameId = nameLookup.Get <long>("strLocalizedTextRetrieverStringID");
            itm.Name   = StringTable.TryGetString(itm.Fqn, nameLookup);
            if (itm.Name == null)
            {
                itm.Name = String.Empty;
            }
            itm.Id = (ulong)(itm.NameId >> 32);

            itm.Quality = Models.ItemQualityExtensions.ToItemQuality((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmBaseQuality", null));
            //if (itm.EnhancementType != EnhancementType.None)
            //{
            itm.Rating = Tables.ItemRating.GetRating(itm.ItemLevel, itm.Quality);
            //}
            //else
            //{
            //itm.Rating = Tables.ItemRating.GetRating(itm.ItemLevel, ItemQuality.Premium);
            //}
            itm.RequiresAlignment         = (bool)gom.Data.ValueOrDefault <bool>("itmAlignmentRequired", false);
            itm.RequiredAlignmentTier     = (int)gom.Data.ValueOrDefault <long>("itmRequiredAlignmentTier", int.MaxValue);
            itm.RequiredAlignmentInverted = (bool)gom.Data.ValueOrDefault <bool>("itmRequiredAlignmentInverted", false);

            itm.Field_4000000FAFE42471 = gom.Data.ValueOrDefault <long>("field_4000000FAFE42471", 0);

            // Required Classes
            itm.RequiredClasses = new ClassSpecList();
            var classMap = (Dictionary <object, object>)gom.Data.ValueOrDefault <Dictionary <object, object> >("itmRequiredClasses", null);

            if (classMap != null)
            {
                foreach (var kvp in classMap)
                {
                    if ((bool)kvp.Value)
                    {
                        var classSpec = ClassSpecLoader.Load((ulong)kvp.Key);
                        if (classSpec == null)
                        {
                            continue;
                        }
                        itm.RequiredClasses.Add(classSpec);
                    }
                }
            }

            itm.RequiredGender          = GenderExtensions.ToGender((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("itmGenderRequired", null));
            itm.RequiredLevel           = (int)gom.Data.ValueOrDefault <long>("itmMinimumLevel", 0);
            itm.RequiredProfession      = Models.ProfessionExtensions.ToProfession((ScriptEnum)gom.Data.ValueOrDefault <ScriptEnum>("prfProfessionRequired", null));
            itm.RequiredProfessionLevel = (int)gom.Data.ValueOrDefault <long>("prfProfessionLevelRequired", 0);
            itm.RequiresSocial          = (bool)gom.Data.ValueOrDefault <bool>("itmSocialScoreRequired", false);
            itm.RequiredSocialTier      = (int)gom.Data.ValueOrDefault <long>("itmRequiredSocialScoreTier", 0);
            itm.RequiredValorRank       = (int)gom.Data.ValueOrDefault <long>("itmRequiredValorRank", 0);

            // Item is a recipe/schematic
            GomObjectData schematic = (GomObjectData)gom.Data.ValueOrDefault <object>("prfLearnedSchematic", null);

            if (schematic != null)
            {
                itm.SchematicId = schematic.Get <ulong>("prfSchematicSpecId");
                itm.Schematic   = SchematicLoader.Load(itm.SchematicId);
            }

            itm.ShieldSpec = ArmorSpecExtensions.ToArmorSpec((long)gom.Data.ValueOrDefault <long>("itmShieldSpec", 0));

            // Valid Inventory Slots
            itm.Slots = new SlotTypeList();
            var slotList = (List <object>)gom.Data.ValueOrDefault <List <object> >("itmSlotTypes", null);

            if (slotList != null)
            {
                foreach (var slot in slotList)
                {
                    SlotType slotType = SlotTypeExtensions.ToSlotType((ScriptEnum)slot);
                    if (SlotTypeExtensions.IgnoreSlot(slotType))
                    {
                        continue;
                    }
                    itm.Slots.Add(slotType);
                }
            }

            // Item Stats
            var stats = (Dictionary <object, object>)gom.Data.ValueOrDefault <Dictionary <object, object> >("itmEquipModStats", null);

            itm.StatModifiers = new ItemStatList();
            if (stats != null)
            {
                foreach (var kvp in stats)
                {
                    ItemStat itmStat = new ItemStat();
                    itmStat.Stat     = StatExtensions.ToStat((ScriptEnum)kvp.Key);
                    itmStat.Modifier = (int)(float)kvp.Value;
                    itm.StatModifiers.Add(itmStat);
                }
            }

            // Combined Stats
            itm.CombinedStatModifiers = new ItemStatList();
            itm.CombinedRequiredLevel = itm.RequiredLevel;
            itm.CombinedRating        = itm.Rating;
            foreach (var stat in itm.StatModifiers)
            {
                var itmStat = new ItemStat();
                itmStat.Stat     = stat.Stat;
                itmStat.Modifier = stat.Modifier;
                itm.CombinedStatModifiers.Add(itmStat);
            }

            foreach (var mod in itm.EnhancementSlots)
            {
                if (mod.Modification != null)
                {
                    if (mod.Slot.IsBaseMod())
                    {
                        if (mod.Modification.RequiredLevel > itm.CombinedRequiredLevel)
                        {
                            itm.CombinedRequiredLevel = mod.Modification.RequiredLevel;
                        }
                        if (mod.Modification.Rating > itm.CombinedRating)
                        {
                            itm.CombinedRating = mod.Modification.Rating;
                        }
                    }

                    foreach (var stat in mod.Modification.CombinedStatModifiers)
                    {
                        ItemStat itmStat = itm.CombinedStatModifiers.FirstOrDefault(s => s.Stat == stat.Stat);
                        if (itmStat == null)
                        {
                            itmStat           = new ItemStat();
                            itmStat.Stat      = stat.Stat;
                            itmStat.Modifier += stat.Modifier;
                            itm.CombinedStatModifiers.Add(itmStat);
                        }
                        else
                        {
                            itmStat.Modifier += stat.Modifier;
                        }
                    }
                }
            }

            //itm.TreasurePackageSpec;
            itm.TreasurePackageId = (long)gom.Data.ValueOrDefault <long>("field_40000013407C89A3", 0);
            itm.TypeBitSet        = (int)(long)gom.Data.ValueOrDefault <long>("itmTypeBitSet", 0);
            itm.UniqueLimit       = (int)gom.Data.ValueOrDefault <long>("itmUniqueLimit", 0);

            itm.UseAbilityId = gom.Data.ValueOrDefault <ulong>("itmUsageAbility", 0);
            itm.UseAbility   = AbilityLoader.Load(itm.UseAbilityId);

            itm.Value           = (int)gom.Data.ValueOrDefault <long>("itmValue", 0);
            itm.VendorStackSize = (int)gom.Data.ValueOrDefault <long>("itmStackVendor", 0);
            itm.WeaponSpec      = WeaponSpecExtensions.ToWeaponSpec((ulong)gom.Data.ValueOrDefault <ulong>("cbtWeaponSpec", 0));

            //ulong dmgType = (ulong)gom.Data.ValueOrDefault<ulong>("cbtDamageType", 0);
            //itm.DamageType = ItemDamageTypeExtensions.ToItemDamageType(dmgType);
            switch (itm.WeaponSpec)
            {
            case WeaponSpec.Lightsaber:
            case WeaponSpec.Polesaber:
            case WeaponSpec.Pistol:
            case WeaponSpec.Rifle:
            case WeaponSpec.SniperRifle:
            case WeaponSpec.AssaultCannon:
            { itm.DamageType = ItemDamageType.Energy; break; }

            case WeaponSpec.Vibroblade:
            case WeaponSpec.VibrobladeTech:
            case WeaponSpec.Vibroknife:
            case WeaponSpec.Shotgun:
            case WeaponSpec.Electrostaff:
            case WeaponSpec.ElectrostaffTech:
            { itm.DamageType = ItemDamageType.Kinetic; break; }

            default:
            { itm.DamageType = ItemDamageType.None; break; }
            }

            itm.IsModdable = ((itm.Quality == ItemQuality.Prototype) && (itm.EnhancementSlots.Count > 1)) || itm.Quality == ItemQuality.Moddable;

            ItemSubCategoryExtensions.SetCategory(itm);

            return(itm);
        }
예제 #2
0
        public static Models.Schematic Load(Models.Schematic schem, GomObject obj)
        {
            if (obj == null)
            {
                return(schem);
            }
            if (schem == null)
            {
                return(null);
            }

            schem.NodeId = obj.Id;
            schem.Fqn    = obj.Name;

            schem.Deprecated         = obj.Data.ValueOrDefault <bool>("prfSchematicDeprecated", false);
            schem.DisableCritical    = obj.Data.ValueOrDefault <bool>("prfDisableCritical", false);
            schem.DisableDisassemble = obj.Data.ValueOrDefault <bool>("prfDisableDisassemble", false);

            ulong itemId = (ulong)obj.Data.ValueOrDefault <ulong>("prfSchematicItemSpec", 0);

            if (itemId > 0)
            {
                schem.Item = ItemLoader.Load(itemId);
                if (schem.Item != null)
                {
                    schem.Id = schem.Item.Id;
                }
                else
                {
                    Console.WriteLine("Schematic references non-existant item: " + schem.Fqn);
                }
            }

            schem.MissionCost       = (int)obj.Data.ValueOrDefault <long>("prfMissionCost", 0);
            schem.MissionFaction    = FactionExtensions.ToFaction((long)obj.Data.ValueOrDefault <long>("prfMissionFaction", 0));
            schem.MissionUnlockable = obj.Data.ValueOrDefault <bool>("prfMissionUnlockable", false);
            schem.MissionLight      = (int)obj.Data.ValueOrDefault <long>("prfMissionRewardLight", 0);
            schem.MissionLightCrit  = (int)obj.Data.ValueOrDefault <long>("prfMissionRewardLightCritical", 0);
            schem.MissionDark       = (int)obj.Data.ValueOrDefault <long>("prfMissionRewardDark", 0);
            schem.MissionDarkCrit   = (int)obj.Data.ValueOrDefault <long>("prfMissionRewardDarkCritical", 0);

            schem.NameId = (ulong)obj.Data.ValueOrDefault <long>("prfSchematicNameId", 0);
            if (schem.NameId > 0)
            {
                schem.Name = missionStrTable.GetText((int)schem.NameId + strOffset, schem.Fqn);
                schem.Id   = schem.NameId;
            }

            if ((schem.Name == null) && (schem.Item != null))
            {
                schem.Name = schem.Item.Name;
            }

            schem.MissionYieldDescriptionId = (int)obj.Data.ValueOrDefault <long>("prfMissionYieldDescriptionId", 0);
            if (schem.MissionYieldDescriptionId > 0)
            {
                schem.MissionYieldDescription = missionStrTable.GetText(schem.MissionYieldDescriptionId + strOffset, schem.Fqn);
            }

            schem.MissionDescriptionId = (int)obj.Data.ValueOrDefault <long>("prfMissionDescriptionId", 0);
            if (schem.MissionDescriptionId > 0)
            {
                schem.MissionDescription = missionStrTable.GetText(schem.MissionDescriptionId + strOffset, schem.Fqn);
            }

            schem.CrewSkillId = ProfessionExtensions.ToProfession((ScriptEnum)obj.Data.ValueOrDefault <ScriptEnum>("prfProfessionRequired", null));
            schem.Subtype     = ProfessionSubtypeExtensions.ToProfessionSubtype((ScriptEnum)obj.Data.ValueOrDefault <ScriptEnum>("prfProfessionSubtype", null));

            schem.SkillGrey   = (int)obj.Data.ValueOrDefault <long>("prfSchematicGrey", 0);
            schem.SkillGreen  = (int)obj.Data.ValueOrDefault <long>("prfSchematicGreen", 0);
            schem.SkillYellow = (int)obj.Data.ValueOrDefault <long>("prfSchematicYellow", 0);
            schem.SkillOrange = (int)obj.Data.ValueOrDefault <long>("prfProfessionLevelRequired", 0);

            schem.TrainingCost = (int)obj.Data.ValueOrDefault <long>("prfTrainingCost", 0);
            schem.Workstation  = WorkstationExtensions.ToWorkstation((ScriptEnum)obj.Data.ValueOrDefault <ScriptEnum>("prfWorkstationRequired", null));

            var materials = (Dictionary <object, object>)obj.Data.ValueOrDefault <Dictionary <object, object> >("prfSchematicMaterials", null);

            if (materials != null)
            {
                int matIdx = 1;
                foreach (var mat_quantity in materials)
                {
                    switch (matIdx)
                    {
                    case 1:
                        schem.Mat1         = ItemLoader.Load((ulong)mat_quantity.Key);
                        schem.Mat1Quantity = (int)(long)mat_quantity.Value;
                        break;

                    case 2:
                        schem.Mat2         = ItemLoader.Load((ulong)mat_quantity.Key);
                        schem.Mat2Quantity = (int)(long)mat_quantity.Value;
                        break;

                    case 3:
                        schem.Mat3         = ItemLoader.Load((ulong)mat_quantity.Key);
                        schem.Mat3Quantity = (int)(long)mat_quantity.Value;
                        break;

                    case 4:
                        schem.Mat4         = ItemLoader.Load((ulong)mat_quantity.Key);
                        schem.Mat4Quantity = (int)(long)mat_quantity.Value;
                        break;

                    case 5:
                        schem.Mat5         = ItemLoader.Load((ulong)mat_quantity.Key);
                        schem.Mat5Quantity = (int)(long)mat_quantity.Value;
                        break;

                    default:
                        throw new InvalidOperationException("Schematic has too many materials!");
                    }

                    matIdx++;
                }
            }

            var researchChance = (Dictionary <object, object>)obj.Data.ValueOrDefault <Dictionary <object, object> >("prfSchematicResearchChances", null);

            if (researchChance != null)
            {
                int rLvl = 1;
                foreach (var r_chance in researchChance)
                {
                    switch (rLvl)
                    {
                    case 1: schem.ResearchChance1 = SchematicResearchChanceExtensions.ToSchematicResearchChance((ScriptEnum)r_chance.Value); break;

                    case 2: schem.ResearchChance2 = SchematicResearchChanceExtensions.ToSchematicResearchChance((ScriptEnum)r_chance.Value); break;

                    case 3: schem.ResearchChance3 = SchematicResearchChanceExtensions.ToSchematicResearchChance((ScriptEnum)r_chance.Value); break;

                    default: throw new InvalidOperationException("This schematic has 4 tiers of research!?!");
                    }

                    rLvl++;
                }
            }

            var craftTime = (List <object>)obj.Data.ValueOrDefault <List <object> >("prfSchematicCraftingTime", null);

            if (craftTime != null)
            {
                int timeIdx = 0;
                foreach (var time in craftTime)
                {
                    switch (timeIdx)
                    {
                    case 0: schem.CraftingTime = (int)(ulong)time / 1000; break;

                    case 1: schem.CraftingTimeT1 = (int)(ulong)time / 1000; break;

                    case 2: schem.CraftingTimeT2 = (int)(ulong)time / 1000; break;

                    case 3: schem.CraftingTimeT3 = (int)(ulong)time / 1000; break;

                    default: throw new InvalidOperationException("This schematic has 4 tiers of research!?!");
                    }

                    timeIdx++;
                }
            }

            var researchMaterials = (Dictionary <object, object>)obj.Data.ValueOrDefault <Dictionary <object, object> >("prfSchematicResearchMaterials", null);

            if (researchMaterials != null)
            {
                int idx = 1;
                foreach (var r_mats in researchMaterials)
                {
                    Dictionary <object, object> matLookup = (Dictionary <object, object>)r_mats.Value;
                    if (matLookup.Count > 1)
                    {
                        throw new InvalidOperationException("Research Tier adds more than one material");
                    }
                    ulong matId       = (ulong)matLookup.First().Key;
                    int   matQuantity = (int)(long)matLookup.First().Value;

                    if (matId > 0)
                    {
                        switch (idx)
                        {
                        case 1:
                            schem.Research1         = ItemLoader.Load(matId);
                            schem.ResearchQuantity1 = matQuantity;
                            break;

                        case 2:
                            schem.Research2         = ItemLoader.Load(matId);
                            schem.ResearchQuantity2 = matQuantity;
                            break;

                        case 3:
                            schem.Research3         = ItemLoader.Load(matId);
                            schem.ResearchQuantity3 = matQuantity;
                            break;

                        default: throw new InvalidOperationException("This schematic has 4 tiers of research!?!");
                        }
                    }
                    idx++;
                }
            }

            if (idMap.Values.Where(s => s.Id == schem.Id).Count() > 0)
            {
                throw new InvalidOperationException("Attempting to set Id of a schematic to one that's already taken");
            }

            return(schem);
        }