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(); } } }