public bool Parse <T>( XElement node, out IFormLink <T> item, ErrorMaskBuilder?errorMask) where T : class, IMajorRecordCommonGetter { throw new NotImplementedException(); }
public static void Relink <TMajorGetter>(this IFormLink <TMajorGetter> link, IReadOnlyDictionary <FormKey, FormKey> mapping) where TMajorGetter : class, IMajorRecordCommonGetter { if (!link.IsNull && mapping.TryGetValue(link.FormKey, out var replacement)) { link.SetTo(replacement); } }
public static void AddPerk(this INpc npc, IFormLink <IPerkGetter> perk, byte rank = 1) { npc.Perks ??= new ExtendedList <PerkPlacement>(); npc.Perks.Add(new PerkPlacement { Perk = perk, Rank = rank }); }
public void Write <T>( MutagenWriter writer, IFormLink <T> item) where T : class, IMajorRecordCommonGetter { FormKeyBinaryTranslation.Instance.Write( writer, item.FormKey); }
/// <summary> /// Locate all of a link's target records in given Link Cache.<br /> /// The winning override will be returned first, and finished by the original defining definition. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <returns>Enumerable of the linked records</returns> /// <typeparam name="TMajor">Major Record type to resolve to</typeparam> public static IEnumerable <TMajor> ResolveAll <TMajor>(this IFormLink <TMajor> link, ILinkCache cache) where TMajor : class, IMajorRecordCommonGetter { if (!link.FormKeyNullable.TryGet(out var formKey)) { return(Enumerable.Empty <TMajor>()); } return(cache.ResolveAll <TMajor>(formKey)); }
/// <summary> /// Attempts to locate link's winning target record in given Link Cache. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <param name="majorRecord">Major Record if located</param> /// <returns>True if successful in linking to record</returns> /// <typeparam name="TMajor">Major Record type to resolve to</typeparam> public static bool TryResolve <TMajor>(this IFormLink <TMajor> link, ILinkCache cache, [MaybeNullWhen(false)] out TMajor majorRecord) where TMajor : class, IMajorRecordCommonGetter { if (!link.FormKeyNullable.TryGet(out var formKey)) { majorRecord = default; return(false); } return(cache.TryResolve <TMajor>(formKey, out majorRecord)); }
/// <summary> /// Locates link winning target record in given Link Cache. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <returns>Located Major Record</returns> /// <exception cref="NullReferenceException">If link was not succesful</exception> /// <typeparam name="TMajor">Major Record type of the FormLink</typeparam> /// <typeparam name="TScopedMajor">Major Record type to resolve to</typeparam> public static TScopedMajor?Resolve <TMajor, TScopedMajor>(this IFormLink <TMajor> link, ILinkCache cache) where TMajor : class, IMajorRecordCommonGetter where TScopedMajor : class, TMajor { if (link.TryResolve <TMajor, TScopedMajor>(cache, out var majorRecord)) { return(majorRecord); } return(null); }
public static void FormLink() { var mod = new SkyrimMod(Utility.LightMasterModKey, SkyrimRelease.SkyrimLE); var light = mod.Lights.AddNew(); var cache = mod.ToImmutableLinkCache(); var link = new FormLink <ISkyrimMajorRecordGetter>(light.FormKey); var nullableLink = new FormLinkNullable <ISkyrimMajorRecordGetter>(light.FormKey); IFormLink <ISkyrimMajorRecordGetter> iLink = link; // Normal resolution link.TryResolve(cache, out var _); link.TryResolve(cache, out ISkyrimMajorRecordGetter _); link.Resolve(cache); link.TryResolve <ILightGetter>(cache, out var _); link.TryResolve(cache, out ILightGetter _); link.Resolve <ILightGetter>(cache); nullableLink.TryResolve(cache, out var _); nullableLink.TryResolve(cache, out ISkyrimMajorRecordGetter _); nullableLink.Resolve(cache); nullableLink.TryResolve <ILightGetter>(cache, out var _); nullableLink.TryResolve(cache, out ILightGetter _); nullableLink.Resolve <ILightGetter>(cache); iLink.TryResolve(cache, out var _); iLink.Resolve(cache); iLink.TryResolve <ISkyrimMajorRecordGetter, ILightGetter>(cache, out var _); iLink.TryResolve(cache, out ILightGetter _); iLink.Resolve <ISkyrimMajorRecordGetter, ILightGetter>(cache); // Context resolution // ToDo // Enable when generic querying is supported //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _); //link.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); //link.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache); link.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _); link.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); link.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache); //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out var _); //nullableLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache, out IModContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter> _); //nullableLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord>(cache); nullableLink.TryResolveContext <ISkyrimMod, ILight, ILightGetter>(cache, out var _); nullableLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); nullableLink.ResolveContext <ISkyrimMod, ILight, ILightGetter>(cache); //iLink.TryResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache, out var _); //iLink.ResolveContext<ISkyrimMod, ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(cache); iLink.TryResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache, out var _); iLink.TryResolveContext(cache, out IModContext <ISkyrimMod, ILight, ILightGetter> _); iLink.ResolveContext <ISkyrimMod, ISkyrimMajorRecordGetter, ILight, ILightGetter>(cache); }
/// <summary> /// Adds a consumed item to the recipe /// </summary> /// <param name="cobj"></param> /// <param name="item">Item to consume</param> /// <param name="count">Item count</param> public static void AddCraftingRequirement(this ConstructibleObject cobj, IFormLink <IItemGetter> item, int count) { cobj.Items ??= new ExtendedList <ContainerEntry>(); cobj.Items.Add(new ContainerEntry() { Item = new ContainerItem() { Item = item, Count = count } }); }
/// <summary> /// Locates link winning target record in given Link Cache. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <returns>Located Major Record</returns> /// <exception cref="NullReferenceException">If link was not succesful</exception> /// <typeparam name="TMajor">Major Record type to resolve to</typeparam> public static TMajor?Resolve <TMajor>(this IFormLink <TMajor> link, ILinkCache cache) where TMajor : class, IMajorRecordCommonGetter { if (link.FormKeyNullable == null) { return(null); } if (link.TryResolve <TMajor>(cache, out var majorRecord)) { return(majorRecord); } return(null); }
/// <summary> /// Locates link winning target record in given Link Cache. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <returns>Located Major Record</returns> /// <exception cref="NullReferenceException">If link was not succesful</exception> /// <typeparam name="TMod">Mod setter type that can be overridden into</typeparam> /// <typeparam name="TMajorSetter">Major Record setter type to resolve to</typeparam> /// <typeparam name="TMajorGetter">Major Record getter type to resolve to</typeparam> public static IModContext <TMod, TMajorSetter, TMajorGetter>?ResolveContext <TMod, TMajorSetter, TMajorGetter>( this IFormLink <TMajorGetter> link, ILinkCache <TMod> cache) where TMod : class, IContextMod <TMod> where TMajorSetter : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (link.TryResolveContext <TMod, TMajorSetter, TMajorGetter>(cache, out var majorRecord)) { return(majorRecord); } return(null); }
/// <summary> /// Adds a condition to the recipe that the user have a given perk /// </summary> /// <param name="cobj"></param> /// <param name="perk"></param> public static void AddCraftingPerkCondition(this ConstructibleObject cobj, IFormLink <IPerkGetter> perk, bool mustHave = true) { cobj.Conditions.Add(new ConditionFloat { Data = new FunctionConditionData { Function = Condition.Function.HasPerk, ParameterOneRecord = perk, }, CompareOperator = CompareOperator.EqualTo, ComparisonValue = mustHave ? 1 : 0, }); }
public bool Parse <T>( MutagenFrame frame, [MaybeNullWhen(false)] out IFormLink <T> item) where T : class, IMajorRecordCommonGetter { if (FormKeyBinaryTranslation.Instance.Parse(frame, out FormKey id)) { item = new FormLink <T>(id); return(true); } item = new FormLink <T>(); return(false); }
/// <summary> /// Attempts to locate link's winning target record in given Link Cache. /// </summary> /// <param name="link">Link to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <param name="majorRecord">Major Record if located</param> /// <returns>True if successful in linking to record</returns> /// <typeparam name="TMod">Mod setter type that can be overridden into</typeparam> /// <typeparam name="TMajorSetter">Major Record setter type to resolve to</typeparam> /// <typeparam name="TMajorGetter">Major Record getter type to resolve to</typeparam> public static bool TryResolveContext <TMod, TMajorSetter, TMajorGetter>( this IFormLink <TMajorGetter> link, ILinkCache <TMod> cache, [MaybeNullWhen(false)] out IModContext <TMod, TMajorSetter, TMajorGetter> majorRecord) where TMod : class, IContextMod <TMod> where TMajorSetter : class, IMajorRecordCommon, TMajorGetter where TMajorGetter : class, IMajorRecordCommonGetter { if (!link.FormKeyNullable.TryGet(out var formKey)) { majorRecord = default; return(false); } return(cache.TryResolveContext <TMajorSetter, TMajorGetter>(formKey, out majorRecord)); }
public override IFormLink <T> ReadJson(JsonReader reader, Type objectType, IFormLink <T>?existingValue, bool hasExistingValue, JsonSerializer serializer) { var name = (string?)reader.Value; if (name == null) { return(new FormLink <T>()); } if (_links.TryGetValue(name, out var r)) { return(r); } throw new InvalidDataException($"Cannot find {typeof(T).Name} with Editor ID {name}"); }
private void CreateAmmoCraftingRecipe(IAmmunitionGetter baseAmmo, IAmmunitionGetter resultAmmo, int inputNum, ushort outputNum, IEnumerable <IFormLink <IItemGetter> > ingredients, IEnumerable <IFormLink <IPerkGetter> > requiredPerks, IFormLink <IPerkGetter>?blockerPerk, IFormLink <IKeywordGetter> craftingBenchKw) { string eid = ""; if (blockerPerk != null) { eid = SPrefixPatcher + SPrefixAmmunition + SPrefixCrafting + resultAmmo.EditorID + baseAmmo.FormKey + blockerPerk.FormKey; } else { eid = SPrefixPatcher + SPrefixAmmunition + SPrefixCrafting + resultAmmo.EditorID + baseAmmo.FormKey; } var newrec = Patch.ConstructibleObjects.AddNew(); newrec.EditorID = eid; newrec.WorkbenchKeyword.SetTo(craftingBenchKw); newrec.CreatedObject.SetTo(resultAmmo); newrec.CreatedObjectCount = outputNum; newrec.AddCraftingRequirement(baseAmmo, inputNum); foreach (var i in ingredients) { newrec.AddCraftingRequirement(i, 1); } foreach (var perk in requiredPerks) { newrec.AddCraftingPerkCondition(perk); } if (blockerPerk != null) { newrec.AddCraftingPerkCondition(blockerPerk, false); } newrec.AddCraftingInventoryCondition(baseAmmo, 1); }
public static FormLinkInformation Factory <TMajorGetter>(IFormLink <TMajorGetter> link) where TMajorGetter : IMajorRecordCommonGetter { return(new FormLinkInformation(link.FormKey, typeof(TMajorGetter))); }
/// <summary> /// Attempts to locate link target in given Link Cache. /// </summary> /// <param name="formLink">FormLink to resolve</param> /// <param name="package">Link Cache to resolve against</param> /// <param name="major">Located record if successful</param> /// <returns>True if link was resolved and a record was retrieved</returns> /// <typeparam name="TMajor">Major Record type to resolve to</typeparam> public static bool TryResolve <TMajor>(this IFormLink <TMajor> formLink, ILinkCache package, out TMajor major) where TMajor : IMajorRecordCommonGetter { major = formLink.Resolve(package); return(major != null); }
/// <summary> /// Compares equality of two links, where rhs is a non nullable link. /// </summary> /// <param name="other">Other link to compare to</param> /// <returns>True if FormKey members are equal</returns> public bool Equals(IFormLink <TMajorGetter>?other) => EqualityComparer <FormKey?> .Default.Equals(this.FormKeyNullable, other?.FormKey);
/// <summary> /// Compares equality of two links. /// </summary> /// <param name="other">Other link to compare to</param> /// <returns>True if FormKey members are equal</returns> public bool Equals(IFormLink <TMajorGetter>?other) => this.FormKey.Equals(other?.FormKey);
/// <summary> /// Locate all of a link's target record contexts in given Link Cache.<br /> /// The winning override will be returned first, and finished by the original defining definition. /// </summary> /// <param name="link">FormLink to resolve</param> /// <param name="cache">Link Cache to resolve against</param> /// <returns>Enumerable of the linked records</returns> /// <typeparam name="TMod">Mod setter type that can be overridden into</typeparam> /// <typeparam name="TMajorGetter">Original links Major Record type</typeparam> /// <typeparam name="TScopedSetter">Inheriting Major Record setter type to scope to</typeparam> /// <typeparam name="TScopedGetter">Inheriting Major Record getter type to scope to</typeparam> public static IEnumerable <IModContext <TMod, TScopedSetter, TScopedGetter> > ResolveAllContexts <TMod, TMajorGetter, TScopedSetter, TScopedGetter>(this IFormLink <TMajorGetter> link, ILinkCache <TMod> cache) where TMod : class, IContextMod <TMod> where TMajorGetter : class, IMajorRecordCommonGetter where TScopedSetter : class, TScopedGetter, IMajorRecordCommon where TScopedGetter : class, TMajorGetter { if (!link.FormKeyNullable.TryGet(out var formKey)) { return(Enumerable.Empty <IModContext <TMod, TScopedSetter, TScopedGetter> >()); } return(cache.ResolveAllContexts <TScopedSetter, TScopedGetter>(formKey)); }
protected override IWeaponGetter CreateItemFromTemplate(IWeaponGetter template, IWeaponGetter like, IFormLink <IObjectEffectGetter> e) { var resolved = e.Resolve(State.LinkCache); var newArmor = Patch.Weapons.DuplicateInAsNewRecord(template); newArmor.SetEditorID( SPrefixPatcher + SPrefixWeapon + template.NameOrEmpty() + resolved.NameOrEmpty(), resolved); newArmor.Template.SetTo(template); newArmor.ObjectEffect.SetTo(e); newArmor.BasicStats !.Value = like.BasicStats !.Value; newArmor.EnchantmentAmount = like.EnchantmentAmount; newArmor.Name = Storage.GetLocalizedEnchantmentName(template, e); return(newArmor); }
public override void WriteJson(JsonWriter writer, IFormLink <T>?value, JsonSerializer serializer) { throw new NotImplementedException(); }
public static IFormLinkGetter <TGetter> AsGetter <TGetter>(this IFormLink <TGetter> link) where TGetter : class, IMajorRecordCommonGetter { return(link); }
/// <summary> /// Given a template, and a existing enchanted item, create a new item with the given enchantment /// </summary> /// <param name="template"></param> /// <param name="like"></param> /// <param name="e"></param> /// <returns></returns> protected abstract TItem CreateItemFromTemplate(TItem template, TItem like, IFormLink <IObjectEffectGetter> e);
/// <summary> /// Adds a condition to the recipe that an item exist in the player's inventory /// </summary> /// <param name="cobj"></param> /// <param name="item"></param> /// <param name="count"></param> public static void AddCraftingInventoryCondition(this ConstructibleObject cobj, IFormLink <ISkyrimMajorRecordGetter> item, int count = 1) { cobj.Conditions.Add(new ConditionFloat { Data = new FunctionConditionData { Function = Condition.Function.GetItemCount, ParameterOneRecord = item }, CompareOperator = CompareOperator.GreaterThanOrEqualTo, ComparisonValue = count }); }
/// <summary> /// Compares equality of two links. /// </summary> /// <param name="other">Other link to compare to</param> /// <returns>True if FormKey members are equal</returns> public bool Equals(IFormLink <TMajor> other) => this.FormKey.Equals(other.FormKey);
public static void AddSpell(this IRace race, IFormLink <ISpellGetter> spell) { race.ActorEffect ??= new ExtendedList <IFormLinkGetter <ISpellRecordGetter> >(); race.ActorEffect.Add(spell); }
/// <summary> /// Takes in a FormLink, and either returns the existing override definition /// from the Group, or attempts to link and copy the given record, inserting it, and then returning it as an override. /// </summary> /// <param name="group">Group to retrieve and/or insert from</param> /// <param name="link">Link to query and add</param> /// <param name="cache">Cache to query link against</param> /// <param name="rec">Retrieved record if successful</param> /// <returns>True if a record was retrieved</returns> public static bool TryGetOrAddAsOverride <TMajor, TMajorGetter>(this IGroupCommon <TMajor> group, IFormLink <TMajorGetter> link, ILinkCache cache, [MaybeNullWhen(false)] out TMajor rec) where TMajor : class, IMajorRecordInternal, TMajorGetter where TMajorGetter : class, IMajorRecordGetter, IBinaryItem { try { if (group.RecordCache.TryGetValue(link.FormKey, out rec)) { return(true); } if (!link.TryResolve <TMajorGetter>(cache, out var getter)) { rec = default; return(false); } rec = GetOrAddAsOverride(group, getter); return(true); } catch (Exception ex) { throw RecordException.Factory(ex, link.FormKey, edid: null); } }
public static void RemoveSpell(this INpc npc, IFormLink <ISpellGetter> spell) { npc.ActorEffect?.Remove(spell); }