void RemoveBundle(InstancedBundle bundle) { foreach (IEntityEffect effect in bundle.liveEffects) { effect.End(); } instancedBundles.Remove(bundle); RaiseOnRemoveBundle(); //Debug.LogFormat("Expired bundle {0} with {1} effects", bundle.settings.Name, bundle.settings.Effects.Length); }
/// <summary> /// Restore instanced bundles save data. /// </summary> public void RestoreInstancedBundleSaveData(EffectBundleSaveData_v1[] data) { ClearBundles(); if (data == null || data.Length == 0) { return; } foreach (EffectBundleSaveData_v1 bundleData in data) { InstancedBundle instancedBundle = new InstancedBundle(); instancedBundle.version = bundleData.version; instancedBundle.bundleType = bundleData.bundleType; instancedBundle.targetType = bundleData.targetType; instancedBundle.elementType = bundleData.elementType; instancedBundle.name = bundleData.name; instancedBundle.iconIndex = bundleData.iconIndex; instancedBundle.casterEntityType = bundleData.casterEntityType; instancedBundle.casterLoadID = bundleData.casterLoadID; instancedBundle.liveEffects = new List <IEntityEffect>(); instancedBundle.caster = GetCasterReference(bundleData.casterEntityType, bundleData.casterLoadID); // Resume effects foreach (EffectSaveData_v1 effectData in bundleData.liveEffects) { IEntityEffect effect = GameManager.Instance.EntityEffectBroker.InstantiateEffect(effectData.key, effectData.effectSettings); if (effect == null) { Debug.LogWarningFormat("RestoreInstancedBundleSaveData() could not restore effect as key '{0}' was not found by broker."); continue; } // Resume effect effect.Resume(effectData, this, instancedBundle.caster); effect.RestoreSaveData(effectData.effectSpecific); instancedBundle.liveEffects.Add(effect); } instancedBundles.Add(instancedBundle); } }
public void AssignBundle(EntityEffectBundle sourceBundle) { // Source bundle must have one or more effects if (sourceBundle.Settings.Effects == null || sourceBundle.Settings.Effects.Length == 0) { Debug.LogWarning("AssignBundle() could not assign bundle as source has no effects"); return; } // Create new instanced bundle and copy settings from source bundle InstancedBundle instancedBundle = new InstancedBundle(); instancedBundle.version = sourceBundle.Settings.Version; instancedBundle.bundleType = sourceBundle.Settings.BundleType; instancedBundle.targetType = sourceBundle.Settings.TargetType; instancedBundle.elementType = sourceBundle.Settings.ElementType; instancedBundle.name = sourceBundle.Settings.Name; instancedBundle.iconIndex = sourceBundle.Settings.IconIndex; instancedBundle.liveEffects = new List <IEntityEffect>(); if (sourceBundle.CasterEntityBehaviour) { instancedBundle.caster = sourceBundle.CasterEntityBehaviour; instancedBundle.casterEntityType = sourceBundle.CasterEntityBehaviour.EntityType; instancedBundle.casterLoadID = GetCasterLoadID(sourceBundle.CasterEntityBehaviour); } // Instantiate all effects in this bundle for (int i = 0; i < sourceBundle.Settings.Effects.Length; i++) { // Instantiate effect IEntityEffect effect = GameManager.Instance.EntityEffectBroker.InstantiateEffect(sourceBundle.Settings.Effects[i]); if (effect == null) { Debug.LogWarningFormat("AssignBundle() could not add effect as key '{0}' was not found by broker."); continue; } // Spell absorption - must have a caster entity set if (sourceBundle.CasterEntityBehaviour) { int absorbSpellPoints; if (TryAbsorption(effect, sourceBundle.Settings.TargetType, sourceBundle.CasterEntityBehaviour.Entity, out absorbSpellPoints)) { // Spell passed all checks and was absorbed - return cost output to target entityBehaviour.Entity.IncreaseMagicka(absorbSpellPoints); // Output "Spell was absorbed." DaggerfallUI.AddHUDText(TextManager.Instance.GetText(textDatabase, "spellAbsorbed")); continue; } } // Start effect effect.Start(this, sourceBundle.CasterEntityBehaviour); // Do not proceed if chance failed if (effect.Properties.SupportChance && effect.Properties.ChanceFunction == ChanceFunction.OnCast && !effect.ChanceSuccess) { // Output failure messages if (isPlayerEntity && sourceBundle.Settings.TargetType == TargetTypes.CasterOnly) { // Output "Spell effect failed." for caster only spells DaggerfallUI.AddHUDText(TextManager.Instance.GetText(textDatabase, "spellEffectFailed")); } else if (isPlayerEntity) { // Output "Save versus spell made." for external contact spells DaggerfallUI.AddHUDText(TextManager.Instance.GetText(textDatabase, "saveVersusSpellMade")); } continue; } // Do not add unflagged incumbent effects // But allow for an icon refresh as duration might have changed and we want to update this sooner than next magic round if (effect is IncumbentEffect && !(effect as IncumbentEffect).IsIncumbent) { RaiseOnAssignBundle(); continue; } // Add effect instancedBundle.liveEffects.Add(effect); // At this point effect is ready and gets initial magic round effect.MagicRound(); } // Add bundles with at least one effect if (instancedBundle.liveEffects.Count > 0) { instancedBundles.Add(instancedBundle); RaiseOnAssignBundle(); Debug.LogFormat("Adding bundle {0}", instancedBundle.GetHashCode()); } }