Beispiel #1
0
        static bool Prefix(Equipment __instance, ref int _enchantmentID, bool _fromSync = false)
        {
            Enchantment enchantment = ResourcesPrefabManager.Instance.GenerateEnchantment(_enchantmentID, __instance.transform);

            if (!(bool)(UnityEngine.Object)enchantment)
            {
                return(false);
            }
            enchantment.ApplyEnchantment(__instance);
            EnchantmentRecipe enchantmentRecipeForId = RecipeManager.Instance.GetEnchantmentRecipeForID(_enchantmentID);

            enchantment.AppliedIncenses = enchantmentRecipeForId.Incenses;
            __instance.m_enchantmentIDs.Add(_enchantmentID);
            __instance.m_activeEnchantments.Add(enchantment);
            __instance.m_enchantmentsHaveChanged = !_fromSync;
            if (_fromSync)
            {
                return(false);
            }
            float durabilityRatio = __instance.DurabilityRatio;

            __instance.RefreshEnchantmentModifiers();
            if ((double)durabilityRatio == (double)__instance.DurabilityRatio)
            {
                return(false);
            }
            __instance.SetDurabilityRatio(durabilityRatio);
            return(false);
        }
        public void Serialize(EnchantmentRecipe recipe, Enchantment enchantment)
        {
            Name     = enchantment.Name;
            RecipeID = recipe.RecipeID;

            TimeOfDay          = recipe.TimeOfDay;
            Temperatures       = recipe.Temperature;
            WindAltarActivated = recipe.WindAltarActivated;
            Regions            = recipe.Region;

            if (recipe.QuestEvent?.Event != null)
            {
                var qEvt = recipe.QuestEvent.Event;
                QuestEvent = qEvt.EventName + " (" + qEvt.Description + ")";
            }

            CompatibleEquipment = new EquipmentData();

            if (recipe.CompatibleEquipments.EquipmentTag != null && recipe.CompatibleEquipments.EquipmentTag.Tag != Tag.None)
            {
                CompatibleEquipment.EquipmentTag = recipe.CompatibleEquipments.EquipmentTag.Tag.TagName;
            }

            if (recipe.CompatibleEquipments.CompatibleEquipments != null)
            {
                var list = new List <IngredientData>();
                foreach (var equip in recipe.CompatibleEquipments.CompatibleEquipments)
                {
                    var data = new IngredientData
                    {
                        Type = equip.Type
                    };
                    if (equip.Type == EnchantmentRecipe.IngredientData.IngredientType.Generic)
                    {
                        data.IngredientTag = equip.IngredientTag.Tag.TagName;
                    }
                    else
                    {
                        data.SpecificItemID = equip.SpecificIngredient.ItemID;
                    }
                    list.Add(data);
                }
                CompatibleEquipment.CompatibleEquipments = list.ToArray();
            }

            if (recipe.PillarDatas != null)
            {
                var list = new List <PillarData>();

                foreach (var pillarData in recipe.PillarDatas)
                {
                    var pillar = new PillarData
                    {
                        Direction = pillarData.Direction,
                        IsFar     = pillarData.IsFar,
                    };
                    var ingList = new List <IngredientData>();
                    foreach (var ingredient in pillarData.CompatibleIngredients)
                    {
                        var ing = new IngredientData
                        {
                            Type = ingredient.Type,
                        };

                        if (ingredient.Type == EnchantmentRecipe.IngredientData.IngredientType.Generic)
                        {
                            ing.IngredientTag = ingredient.IngredientTag.Tag.TagName;
                        }
                        else
                        {
                            ing.SpecificItemID = ingredient.SpecificIngredient.ItemID;
                        }

                        ingList.Add(ing);
                    }
                    pillar.CompatibleIngredients = ingList.ToArray();

                    list.Add(pillar);
                }

                PillarDatas = list.ToArray();
            }

            if (recipe.Weather != null)
            {
                var weatherList = new List <WeatherCondition>();
                foreach (var weather in recipe.Weather)
                {
                    weatherList.Add(new WeatherCondition
                    {
                        Invert      = weather.Invert,
                        WeatherType = weather.Weather
                    });
                }
                Weather = weatherList.ToArray();
            }

            Result = DM_Enchantment.ParseEnchantment(enchantment);
        }
        // ======== Serializing Enchantment into a Template =========

        public static SL_EnchantmentRecipe SerializeEnchantment(EnchantmentRecipe recipe)
        {
            var enchantment = ResourcesPrefabManager.Instance.GetEnchantmentPrefab(recipe.ResultID);

            var template = new SL_EnchantmentRecipe
            {
                Name          = enchantment.Name,
                Description   = enchantment.Description,
                EnchantmentID = recipe.RecipeID,

                IncenseItemID      = recipe.PillarDatas?[0]?.CompatibleIngredients?[0].SpecificIngredient?.ItemID ?? -1,
                TimeOfDay          = recipe.TimeOfDay,
                Areas              = recipe.Region,
                Temperature        = recipe.Temperature,
                WindAltarActivated = recipe.WindAltarActivated,

                IsEnchantingGuildRecipe = recipe.TableIsInBuilding,

                EnchantTime        = enchantment.EnchantTime,
                HealthAbsorbRatio  = enchantment.HealthAbsorbRatio,
                StaminaAbsorbRatio = enchantment.StaminaAbsorbRatio,
                ManaAbsorbRatio    = enchantment.ManaAbsorbRatio,
                Indestructible     = enchantment.Indestructible,
                TrackDamageRatio   = enchantment.TrackDamageRatio
            };

            if (recipe.PillarDatas != null)
            {
                var pillarList = new List <PillarData>();
                foreach (var pillarData in recipe.PillarDatas)
                {
                    var data = new PillarData
                    {
                        Direction = (Directions)pillarData.Direction,
                        IsFar     = pillarData.IsFar,
                    };
                    pillarList.Add(data);
                }
                template.PillarDatas = pillarList.ToArray();
            }

            var compatibleEquipment = new EquipmentData
            {
                RequiredTag = recipe.CompatibleEquipments.EquipmentTag.Tag.TagName
            };

            if (recipe.CompatibleEquipments.CompatibleEquipments != null)
            {
                var equipList = new List <IngredientData>();
                foreach (var equipData in recipe.CompatibleEquipments.CompatibleEquipments)
                {
                    var data = new IngredientData
                    {
                        SelectorType = (IngredientTypes)equipData.Type
                    };
                    if (data.SelectorType == IngredientTypes.SpecificItem)
                    {
                        data.SelectorValue = equipData.SpecificIngredient?.ItemID.ToString();
                    }
                    else
                    {
                        data.SelectorValue = equipData.IngredientTag.Tag.TagName;
                    }
                    equipList.Add(data);
                }
                compatibleEquipment.Equipments = equipList.ToArray();
            }
            template.CompatibleEquipment = compatibleEquipment;

            // Parse the actual Enchantment effects

            if (enchantment.transform.childCount > 0)
            {
                var effects = new List <SL_EffectTransform>();
                foreach (Transform child in enchantment.transform)
                {
                    var effectsChild = SL_EffectTransform.ParseTransform(child);

                    if (effectsChild.HasContent)
                    {
                        effects.Add(effectsChild);
                    }
                }
                template.Effects = effects.ToArray();
            }

            if (enchantment.AdditionalDamages != null)
            {
                var list = new List <AdditionalDamage>();
                foreach (var addedDmg in enchantment.AdditionalDamages)
                {
                    list.Add(new AdditionalDamage
                    {
                        AddedDamageType  = addedDmg.BonusDamageType,
                        ConversionRatio  = addedDmg.ConversionRatio,
                        SourceDamageType = addedDmg.SourceDamageType
                    });
                }
                template.AddedDamages = list.ToArray();
            }
            if (enchantment.StatModifications != null)
            {
                var list = new List <StatModification>();
                foreach (var statMod in enchantment.StatModifications)
                {
                    list.Add(new StatModification
                    {
                        Stat  = statMod.Name,
                        Type  = statMod.Type,
                        Value = statMod.Value
                    });
                }
                template.StatModifications = list.ToArray();
            }

            if (enchantment.DamageBonus != null)
            {
                template.FlatDamageAdded = SL_Damage.ParseDamageList(enchantment.DamageBonus).ToArray();
            }
            if (enchantment.DamageModifier != null)
            {
                template.DamageModifierBonus = SL_Damage.ParseDamageList(enchantment.DamageModifier).ToArray();
            }
            if (enchantment.ElementalResistances != null)
            {
                template.DamageResistanceBonus = SL_Damage.ParseDamageList(enchantment.ElementalResistances).ToArray();
            }

            template.GlobalStatusResistance = enchantment.GlobalStatusResistance;

            return(template);
        }