public override PayloadCallbackResults?EnchantmentPayloadCallback(EnchantmentPayloadFlags context, EnchantmentParam?param = null, DaggerfallEntityBehaviour sourceEntity = null, DaggerfallEntityBehaviour targetEntity = null, DaggerfallUnityItem sourceItem = null, int sourceDamage = 0) { base.EnchantmentPayloadCallback(context, param, sourceEntity, targetEntity, sourceItem, sourceDamage); // Validate if (context != EnchantmentPayloadFlags.Equipped || param == null || sourceEntity == null || sourceItem == null) { return(null); } // Get caster effect manager EntityEffectManager casterManager = sourceEntity.GetComponent <EntityEffectManager>(); if (!casterManager) { return(null); } // Cast when held enchantment invokes a spell bundle that is permanent until item is removed if (!string.IsNullOrEmpty(param.Value.CustomParam)) { // TODO: Instantiate a custom spell bundle } else { // Instantiate a classic spell bundle SpellRecord.SpellRecordData spell; if (GameManager.Instance.EntityEffectBroker.GetClassicSpellRecord(param.Value.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; casterManager.AssignBundle(bundle, AssignBundleFlags.BypassSavingThrows); // Play cast sound on equip for player only if (casterManager.IsPlayerEntity) { casterManager.PlayCastSound(sourceEntity, casterManager.GetCastSoundID(bundle.Settings.ElementType)); } // TODO: Apply durability loss to equipped item on equip and over time // http://en.uesp.net/wiki/Daggerfall:Magical_Items#Durability_of_Magical_Items } } } return(null); }
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(); } } }