Beispiel #1
0
        /// <summary>
        /// Determines whether this list contains the specified form.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <returns></returns>
        public bool Contains(NetScriptFramework.SkyrimSE.TESForm form)
        {
            if (form == null)
            {
                return(false);
            }

            return(Contains(form.FormId));
        }
        internal static bool IsTemperable(NetScriptFramework.SkyrimSE.TESForm form)
        {
            if (form == null)
            {
                return(false);
            }

            var armor = form as NetScriptFramework.SkyrimSE.TESObjectARMO;

            if (armor != null)
            {
                int tries = 0;
                while (armor != null && tries++ < 10)
                {
                    if (_formIds.Contains(armor.FormId))
                    {
                        return(true);
                    }

                    armor = armor.TemplateArmor;
                }

                return(false);
            }

            var weap = form as NetScriptFramework.SkyrimSE.TESObjectWEAP;

            if (weap != null)
            {
                int tries = 0;
                while (weap != null && tries++ < 10)
                {
                    if (_formIds.Contains(weap.FormId))
                    {
                        return(true);
                    }

                    weap = weap.TemplateWeapon;
                }

                return(false);
            }

            return(false);
        }
        internal static float Calculate(NetScriptFramework.SkyrimSE.TESForm form)
        {
            if (form == null || AllMap.Count == 0)
            {
                return(1.0f);
            }

            float amt = 1.0f;
            float?mat = null;

            var kwForm = form as NetScriptFramework.SkyrimSE.BGSKeywordForm;

            if (kwForm != null)
            {
                int count = kwForm.Count;
                if (count != 0)
                {
                    var buf = kwForm.Keywords;
                    if (buf != IntPtr.Zero)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            var kwPtr = NetScriptFramework.Memory.ReadPointer(buf + 8 * i);
                            if (kwPtr == IntPtr.Zero)
                            {
                                continue;
                            }

                            var kw = NetScriptFramework.MemoryObject.FromAddress <NetScriptFramework.SkyrimSE.BGSKeyword>(kwPtr);
                            if (kw != null)
                            {
                                var kwt = kw.KeywordText;
                                if (kwt != null)
                                {
                                    string tx = kw.KeywordText.Text;
                                    if (!string.IsNullOrEmpty(tx))
                                    {
                                        float tmp;
                                        if (AllMap.TryGetValue(tx, out tmp))
                                        {
                                            if (ItemDurabilityPlugin.Settings.DebugMessages)
                                            {
                                                ItemDurabilityPlugin.DebugMsg("Calculating keyword modifier " + tx + "=" + tmp + " for item " + form.ToString());
                                            }

                                            if (IsMaterial(tx))
                                            {
                                                if (mat.HasValue)
                                                {
                                                    mat = Math.Min(mat.Value, tmp);
                                                }
                                                else
                                                {
                                                    mat = tmp;
                                                }
                                            }
                                            else
                                            {
                                                amt *= tmp;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (!mat.HasValue)
            {
                float tmp;
                if (AllMap.TryGetValue("_DefaultMissingMaterial", out tmp))
                {
                    mat = tmp;
                }
                else
                {
                    mat = 1.0f;
                }
            }

            return(amt * mat.Value);
        }