private static NWItem CopyWeaponAppearance(NWPlayer oPC, NWItem oSource, NWItem oDest, bool copyPropsAndVars) { NWPlaceable oTempStorage = (GetObjectByTag("OUTFIT_BARREL")); oSource.SetLocalString("TEMP_OUTFIT_UUID", oPC.GlobalID.ToString()); uint oCopy = CopyItem(oDest.Object, oTempStorage.Object, true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponModel, 0, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponModel, 0), true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponColor, 0, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponColor, 0), true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponModel, 1, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponModel, 1), true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponColor, 1, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponColor, 1), true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponModel, 2, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponModel, 2), true); oCopy = CopyItemAndModify(oCopy, ItemAppearanceType.WeaponColor, 2, (int)GetItemAppearance(oSource, ItemAppearanceType.WeaponColor, 2), true); SetName(oCopy, GetName(oSource)); SetDescription(oCopy, GetDescription(oSource)); //LocalVariableService.CopyVariables(oSource, oCopy); NWItem oFinal = (CopyItem(oCopy, oPC.Object, true)); oFinal.DeleteLocalString("TEMP_OUTFIT_UUID"); if (copyPropsAndVars) { // strip all item props from new item foreach (ItemProperty itemProp in oFinal.ItemProperties) { RemoveItemProperty(oFinal, itemProp); } // add all item props from original item to new item foreach (ItemProperty itemProp in oSource.ItemProperties) { AddItemProperty(DurationType.Permanent, itemProp, oFinal); } // finally, copy local vars LocalVariableService.CopyVariables(oSource, oFinal); } DestroyObject(oCopy); oDest.Destroy(); foreach (NWItem item in oTempStorage.InventoryItems) { if (item.GetLocalString("TEMP_OUTFIT_UUID") == oPC.GlobalID.ToString()) { item.Destroy(); } } return(oFinal); }
private static SerializedObjectData ProcessVersion6LightsaberItem(NWItem item) { if (item.CustomItemType != CustomItemType.Lightsaber && item.CustomItemType != CustomItemType.Saberstaff) { return(new SerializedObjectData(null, null)); } NWPlaceable storage = _.GetObjectByTag("MIGRATION_STORAGE"); NWItem newVersion = _.CreateItemOnObject(item.Resref, storage); List <ItemProperty> ipsToAdd = new List <ItemProperty>(); // There's a quirk with NWN in how it handles removing of item properties. // IPs don't get removed immediately - instead, they get removed after the script exits. // Because we're serializing during this process, it causes us to get duplicate item properties // since they haven't actually been removed yet. // To work around this, we return both the serialized item as well as the item properties we need // to add to the item once it's been deserialized. // Nasty workaround, but it does work! foreach (var ip in item.ItemProperties) { ipsToAdd.Add(ip); } // Copy all local variables from old to new version. LocalVariableService.CopyVariables(item, newVersion); // Destroy the old item. item.Destroy(); // We return the serialized value. Be sure we do this before destroying the object. // The reason for this is to ensure we don't hit an infinite loop. The calling method uses a loop iterating // over the player's inventory. Creating an item will cause an infinite loop to happen. string retVal = SerializationService.Serialize(newVersion); // Destroy the copy on the container. newVersion.Destroy(); return(new SerializedObjectData(retVal, ipsToAdd)); }
public static void OnChestUsed(NWPlaceable oChest) { NWPlayer oPC = (_.GetLastUsedBy()); if (!oPC.IsPlayer) { return; } NWPlaceable oCopy = (_.CreateObject(_.OBJECT_TYPE_PLACEABLE, SearchSiteCopyResref, oChest.Location)); oCopy.Name = oChest.Name; _.SetFacingPoint(oPC.Position); LocalVariableService.CopyVariables(oChest, oCopy); oPC.AssignCommand(() => { _.ActionInteractObject(oCopy.Object); }); }