/// <summary> /// /// ---------------------------------------------------------------------------- /// Add an item property in a safe fashion, preventing unwanted stacking /// Parameters: /// oItem - the item to add the property to /// ip - the itemproperty to add /// fDuration - set 0.0f to add the property permanent, anything else is temporary /// nAddItemPropertyPolicy - How to handle existing properties. Valid values are: /// X2_IP_ADDPROP_POLICY_REPLACE_EXISTING - remove any property of the same type, subtype, durationtype before adding; /// X2_IP_ADDPROP_POLICY_KEEP_EXISTING - do not add if any property with same type, subtype and durationtype already exists; /// X2_IP_ADDPROP_POLICY_IGNORE_EXISTING - add itemproperty in any case - Do not Use with OnHit or OnHitSpellCast props! /// bIgnoreDurationType - If set to TRUE, an item property will be considered identical even if the DurationType is different. Be careful when using this /// with X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, as this could lead to a temporary item property removing a permanent one /// bIgnoreSubType - If set to TRUE an item property will be considered identical even if the SubType is different. /// /// ---------------------------------------------------------------------------- /// </summary> /// <param name="oItem"></param> /// <param name="ip"></param> /// <param name="fDuration"></param> /// <param name="nAddItemPropertyPolicy"></param> /// <param name="bIgnoreDurationType"></param> /// <param name="bIgnoreSubType"></param> public void IPSafeAddItemProperty(NWItem oItem, ItemProperty ip, float fDuration, AddItemPropertyPolicy nAddItemPropertyPolicy, bool bIgnoreDurationType, bool bIgnoreSubType) { int nType = _.GetItemPropertyType(ip); int nSubType = _.GetItemPropertySubType(ip); int nDuration; // if duration is 0.0f, make the item property permanent if (fDuration == 0.0f) { nDuration = NWScript.DURATION_TYPE_PERMANENT; } else { nDuration = NWScript.DURATION_TYPE_TEMPORARY; } int nDurationCompare = nDuration; if (bIgnoreDurationType) { nDurationCompare = -1; } if (nAddItemPropertyPolicy == AddItemPropertyPolicy.ReplaceExisting) { // remove any matching properties if (bIgnoreSubType) { nSubType = -1; } IPRemoveMatchingItemProperties(oItem, nType, nDurationCompare, nSubType); } else if (nAddItemPropertyPolicy == AddItemPropertyPolicy.KeepExisting) { // do not replace existing properties if (IPGetItemHasProperty(oItem, ip, nDurationCompare, bIgnoreSubType)) { return; // item already has property, return } } else //X2_IP_ADDPROP_POLICY_IGNORE_EXISTING { } if (nDuration == NWScript.DURATION_TYPE_PERMANENT) { _.AddItemProperty(nDuration, ip, oItem.Object); } else { _.AddItemProperty(nDuration, ip, oItem.Object, fDuration); } }