public void CopyVariables(NWObject oSource, NWObject oCopy)
        {
            int variableCount = _nwnxObject.GetLocalVariableCount(oSource);

            for (int variableIndex = 0; variableIndex < variableCount - 1; variableIndex++)
            {
                LocalVariable stCurVar = _nwnxObject.GetLocalVariable(oSource, variableIndex);

                switch (stCurVar.Type)
                {
                case LocalVariableType.Int:
                    oCopy.SetLocalInt(stCurVar.Key, oSource.GetLocalInt(stCurVar.Key));
                    break;

                case LocalVariableType.Float:
                    oCopy.SetLocalFloat(stCurVar.Key, oSource.GetLocalFloat(stCurVar.Key));
                    break;

                case LocalVariableType.String:
                    oCopy.SetLocalString(stCurVar.Key, oSource.GetLocalString(stCurVar.Key));
                    break;

                case LocalVariableType.Object:
                    oCopy.SetLocalObject(stCurVar.Key, oSource.GetLocalObject(stCurVar.Key));
                    break;

                case LocalVariableType.Location:
                    oCopy.SetLocalLocation(stCurVar.Key, oSource.GetLocalLocation(stCurVar.Key));
                    break;
                }
            }
        }
示例#2
0
        public bool Run(params object[] args)
        {
            int type = _.GetInventoryDisturbType();

            if (type != INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(true);
            }
            NWPlaceable device      = Object.OBJECT_SELF;
            NWPlayer    player      = _.GetLastDisturbed();
            NWItem      item        = _.GetInventoryDisturbItem();
            var         componentIP = item.ItemProperties.FirstOrDefault(x => _.GetItemPropertyType(x) == (int)CustomItemPropertyType.ComponentType);

            // Not a component. Return the item.
            if (componentIP == null)
            {
                _item.ReturnItem(player, item);
                player.FloatingText("You cannot scrap this item.");
                return(false);
            }

            // Remove the item properties
            foreach (var ip in item.ItemProperties)
            {
                var ipType = _.GetItemPropertyType(ip);
                if (ipType != (int)CustomItemPropertyType.ComponentType)
                {
                    _.RemoveItemProperty(item, ip);
                }
            }

            // Remove local variables (except the global ID)
            int varCount = _nwnxObject.GetLocalVariableCount(item);

            for (int index = varCount - 1; index >= 0; index--)
            {
                var localVar = _nwnxObject.GetLocalVariable(item, index);

                if (localVar.Key != "GLOBAL_ID")
                {
                    switch (localVar.Type)
                    {
                    case LocalVariableType.Int:
                        item.DeleteLocalInt(localVar.Key);
                        break;

                    case LocalVariableType.Float:
                        item.DeleteLocalFloat(localVar.Key);
                        break;

                    case LocalVariableType.String:
                        item.DeleteLocalString(localVar.Key);
                        break;

                    case LocalVariableType.Object:
                        item.DeleteLocalObject(localVar.Key);
                        break;

                    case LocalVariableType.Location:
                        item.DeleteLocalLocation(localVar.Key);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            if (!item.Name.Contains("(SCRAPPED)"))
            {
                item.Name = item.Name + " (SCRAPPED)";
            }

            device.AssignCommand(() =>
            {
                _.ActionGiveItem(item, player);
            });

            return(true);
        }