Example #1
0
        private void EnchantmentSecondaryPicker_OnUseSelectedItem()
        {
            // Get enchantment tagged to selected item
            ListBox.ListItem listItem = enchantmentSecondaryPicker.ListBox.SelectedValue;
            if (listItem.tag == null)
            {
                throw new Exception(string.Format("ListItem '{0}' has no EnchantmentSettings tag", listItem.textLabel.Text));
            }

            // Get enchantment settings
            EnchantmentSettings enchantmentSettings = (EnchantmentSettings)listItem.tag;
            IEntityEffect       enchantmentEffect   = GameManager.Instance.EntityEffectBroker.GetEffectTemplate(enchantmentSettings.EffectKey);
            EnchantmentParam    enchantmentParam    = new EnchantmentParam()
            {
                ClassicParam = enchantmentSettings.ClassicParam, CustomParam = enchantmentSettings.CustomParam
            };

            // Get forced enchantments for this effect
            EnchantmentSettings[] forcedPowers         = null;
            EnchantmentSettings[] forcedSideEffects    = null;
            ForcedEnchantmentSet? forcedEnchantmentSet = enchantmentEffect.GetForcedEnchantments(enchantmentParam);

            if (forcedEnchantmentSet != null)
            {
                // Sort forced enchantments into powers and side effects
                SortForcedEnchantments(enchantmentSettings, forcedEnchantmentSet.Value, out forcedPowers, out forcedSideEffects);

                // Check for overflow from automatic enchantments and display "no room in item..."
                // Also adding +1 to account for incoming enchantment
                if (powersList.EnchantmentCount + sideEffectsList.EnchantmentCount + forcedPowers.Length + forcedSideEffects.Length + 1 > 10)
                {
                    DaggerfallUI.MessageBox(TextManager.Instance.GetText(textDatabase, "noRoomInItem"));
                    return;
                }
            }

            // Add selected enchantment settings to powers/side-effects
            AddEnchantmentSettings(enchantmentSettings);
            AddForcedPowers(forcedPowers);
            AddForcedSideEffects(forcedSideEffects);

            // Close effect pickers
            enchantmentPrimaryPicker.CloseWindow();
            enchantmentSecondaryPicker.CloseWindow();
        }
        protected virtual void InstantiateSpellBundle(EnchantmentParam param, DaggerfallEntityBehaviour sourceEntity, DaggerfallUnityItem sourceItem, EntityEffectManager casterManager, bool recast = false)
        {
            if (!string.IsNullOrEmpty(param.CustomParam))
            {
                // TODO: Instantiate a custom spell bundle
            }
            else
            {
                // Instantiate a classic spell bundle
                SpellRecord.SpellRecordData spell;
                if (GameManager.Instance.EntityEffectBroker.GetClassicSpellRecord(param.ClassicParam, out spell))
                {
                    UnityEngine.Debug.LogFormat("CastWhenHeld callback found enchantment '{0}'", spell.spellName);

                    // Create effect bundle settings from classic spell
                    EffectBundleSettings bundleSettings;
                    if (GameManager.Instance.EntityEffectBroker.ClassicSpellRecordDataToEffectBundleSettings(spell, BundleTypes.HeldMagicItem, out bundleSettings))
                    {
                        // Assign bundle
                        EntityEffectBundle bundle = new EntityEffectBundle(bundleSettings, sourceEntity);
                        bundle.FromEquippedItem = sourceItem;
                        bundle.AddRuntimeFlags(BundleRuntimeFlags.ItemRecastEnabled);
                        casterManager.AssignBundle(bundle, AssignBundleFlags.BypassSavingThrows);

                        // Play cast sound on equip for player only
                        if (casterManager.IsPlayerEntity)
                        {
                            casterManager.PlayCastSound(sourceEntity, casterManager.GetCastSoundID(bundle.Settings.ElementType), true);
                        }

                        // Classic uses an item last "cast when held" effect spell cost to determine its durability loss on equip
                        // Here, all effects are considered, as it seems more coherent to do so
                        if (!recast)
                        {
                            int amount = FormulaHelper.CalculateCastingCost(spell, false);
                            sourceItem.LowerCondition(amount, sourceEntity.Entity, sourceEntity.Entity.Items);
                            //UnityEngine.Debug.LogFormat("CastWhenHeld degraded '{0}' by {1} durability points on equip. {2}/{3} remaining.", sourceItem.LongName, amount, sourceItem.currentCondition, sourceItem.maxCondition);
                        }
                    }

                    // Store equip time as last reroll time
                    sourceItem.timeEffectsLastRerolled = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime();
                }
            }
        }
        void InstantiateSpellBundle(EnchantmentParam param, DaggerfallEntityBehaviour sourceEntity, DaggerfallUnityItem sourceItem, EntityEffectManager casterManager)
        {
            if (!string.IsNullOrEmpty(param.CustomParam))
            {
                // TODO: Instantiate a custom spell bundle
            }
            else
            {
                // Instantiate a classic spell bundle
                SpellRecord.SpellRecordData spell;
                if (GameManager.Instance.EntityEffectBroker.GetClassicSpellRecord(param.ClassicParam, out spell))
                {
                    UnityEngine.Debug.LogFormat("CastWhenHeld callback found enchantment '{0}'", spell.spellName);

                    // Create effect bundle settings from classic spell
                    EffectBundleSettings bundleSettings;
                    if (GameManager.Instance.EntityEffectBroker.ClassicSpellRecordDataToEffectBundleSettings(spell, BundleTypes.HeldMagicItem, out bundleSettings))
                    {
                        // Assign bundle
                        EntityEffectBundle bundle = new EntityEffectBundle(bundleSettings, sourceEntity);
                        bundle.FromEquippedItem = sourceItem;
                        bundle.AddRuntimeFlags(BundleRuntimeFlags.ItemRecastEnabled);
                        casterManager.AssignBundle(bundle, AssignBundleFlags.BypassSavingThrows);

                        // Play cast sound on equip for player only
                        if (casterManager.IsPlayerEntity)
                        {
                            casterManager.PlayCastSound(sourceEntity, casterManager.GetCastSoundID(bundle.Settings.ElementType), true);
                        }

                        // TODO: Apply durability loss to equipped item on equip
                        // http://en.uesp.net/wiki/Daggerfall:Magical_Items#Durability_of_Magical_Items
                    }

                    // Store equip time as last reroll time
                    sourceItem.timeEffectsLastRerolled = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime();
                }
            }
        }
Example #4
0
        private void EnchantmentPrimaryPicker_OnUseSelectedItem()
        {
            // Clear existing
            enchantmentSecondaryPicker.ListBox.ClearItems();

            // Get the effect template tagged to selected item
            ListBox.ListItem listItem = enchantmentPrimaryPicker.ListBox.SelectedValue;
            IEntityEffect    effect   = listItem.tag as IEntityEffect;

            if (effect == null)
            {
                throw new Exception(string.Format("ListItem '{0}' has no IEntityEffect tag", listItem.textLabel.Text));
            }

            // Filter enchantments based on effect key
            EnchantmentSettings[] filteredEnchantments = GetFilteredEnchantments(effect);

            // If this is a singleton effect with no secondary options then add directly to powers/side-effects
            if (filteredEnchantments.Length == 1)
            {
                AddEnchantmentSettings(filteredEnchantments[0]);
                enchantmentPrimaryPicker.CloseWindow();
                return;
            }

            // Order filtered list by alpha when requested by effect flags
            if (effect.HasItemMakerFlags(ItemMakerFlags.AlphaSortSecondaryList))
            {
                filteredEnchantments = filteredEnchantments.OrderBy(o => o.SecondaryDisplayName).ToArray();
            }

            // User must select from available secondary enchantment types
            EnchantmentSettings[] currentPowers      = powersList.GetEnchantments();
            EnchantmentSettings[] currentSideEffects = sideEffectsList.GetEnchantments();
            foreach (EnchantmentSettings enchantment in filteredEnchantments)
            {
                // Filter out enchantment when multiple instances not allowed
                if (!effect.HasItemMakerFlags(ItemMakerFlags.AllowMultipleSecondaryInstances))
                {
                    if (ContainsEnchantmentSettings(enchantment))
                    {
                        continue;
                    }
                }

                // Filter if any current secondary enchantments are exclusive to this one
                EnchantmentParam comparerParam = new EnchantmentParam()
                {
                    ClassicParam = enchantment.ClassicParam, CustomParam = enchantment.CustomParam
                };
                if (effect.IsEnchantmentExclusiveTo(currentPowers, comparerParam) || effect.IsEnchantmentExclusiveTo(currentSideEffects, comparerParam))
                {
                    continue;
                }

                enchantmentSecondaryPicker.ListBox.AddItem(enchantment.SecondaryDisplayName, -1, enchantment);
            }

            enchantmentSecondaryPicker.ListBox.SelectedIndex = 0;
            uiManager.PushWindow(enchantmentSecondaryPicker);
        }