예제 #1
0
        public static void Impound(Guid playerID, NWItem item)
        {
            PCImpoundedItem structureImpoundedItem;

            // Processing a container, impound it's contents first.
            if (item.HasInventory)
            {
                foreach (NWItem inventoryItem in item.InventoryItems)
                {
                    structureImpoundedItem = new PCImpoundedItem
                    {
                        DateImpounded = DateTime.UtcNow,
                        PlayerID      = playerID,
                        ItemObject    = SerializationService.Serialize(inventoryItem),
                        ItemTag       = inventoryItem.Tag,
                        ItemResref    = inventoryItem.Resref,
                        ItemName      = inventoryItem.Name
                    };
                    DataService.SubmitDataChange(structureImpoundedItem, DatabaseActionType.Insert);
                }
            }

            // Impound parameter item.
            structureImpoundedItem = new PCImpoundedItem
            {
                DateImpounded = DateTime.UtcNow,
                PlayerID      = playerID,
                ItemObject    = SerializationService.Serialize(item),
                ItemTag       = item.Tag,
                ItemResref    = item.Resref,
                ItemName      = item.Name
            };
            DataService.SubmitDataChange(structureImpoundedItem, DatabaseActionType.Insert);
        }
예제 #2
0
        public static void Impound(Guid playerID, NWItem item)
        {
            PCImpoundedItem structureImpoundedItem = new PCImpoundedItem
            {
                DateImpounded = DateTime.UtcNow,
                PlayerID      = playerID,
                ItemObject    = SerializationService.Serialize(item),
                ItemTag       = item.Tag,
                ItemResref    = item.Resref,
                ItemName      = item.Name
            };

            DataService.SubmitDataChange(structureImpoundedItem, DatabaseActionType.Insert);
        }
예제 #3
0
        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));
        }
예제 #4
0
        private static void SaveChestInventory(NWPlayer oPC, NWPlaceable oChest, bool resetTimeLock)
        {
            int          chestID = oChest.GetLocalInt(SearchSiteIDVariableName);
            PCSearchSite entity  = DataService.SingleOrDefault <PCSearchSite>(x => x.PlayerID == oPC.GlobalID && x.SearchSiteID == chestID);

            int      lockHours = RandomService.Random(2, 5);
            DateTime lockTime  = DateTime.UtcNow.AddHours(lockHours);

            if (entity != null)
            {
                if (resetTimeLock)
                {
                    lockTime = entity.UnlockDateTime;
                }
                DataService.SubmitDataChange(entity, DatabaseActionType.Delete);
            }

            entity = new PCSearchSite
            {
                PlayerID       = oPC.GlobalID,
                SearchSiteID   = chestID,
                UnlockDateTime = lockTime
            };

            foreach (NWItem item in oChest.InventoryItems)
            {
                if (item.GetLocalInt("QUEST_ID") <= 0)
                {
                    PCSearchSiteItem itemEntity = new PCSearchSiteItem
                    {
                        SearchItem   = SerializationService.Serialize(item),
                        SearchSiteID = entity.SearchSiteID
                    };

                    DataService.SubmitDataChange(itemEntity, DatabaseActionType.Insert);
                }
            }
        }
예제 #5
0
        private static void MigrateModuleVersion()
        {
            var         config  = DataService.ServerConfiguration.Get();
            NWPlaceable storage = _.GetObjectByTag("MIGRATION_STORAGE");

            // VERSION 1: Apply new AC rules to all items in persistent storage.
            if (config.ModuleVersion < 1)
            {
                // Loop through all persistent storage sources and run the process which converts AC.
                // Re-serialize it and submit a data change. Then delete the temporary item from temp storage.
                Console.WriteLine("Processing module migration #1. This may take a while.");

                // This is one rare scenario where we want to get data directly from the database, change it, and then write it synchronously.
                // This data is not loaded at boot time, but rather loaded and cached as players log in. So if we were to pull from the DataService's
                // cache, we wouldn't get any of the data as it hasn't loaded yet.
                // This procedure is slow but it only happens one time during the lifespan of the server and then it's finished.

                // BankItem
                foreach (var item in DataService.Connection.GetAll <BankItem>())
                {
                    NWItem deserialized = SerializationService.DeserializeItem(item.ItemObject, storage);
                    PlayerMigrationService.ProcessVersion6_DeflateItemStats(deserialized);
                    ProcessVersion1LightsaberItem(deserialized);
                    item.ItemObject = SerializationService.Serialize(deserialized);
                    DataService.Connection.Update(item);
                    deserialized.Destroy();
                }
                Console.WriteLine("Processed BankItem");

                // PCBaseStructureItem
                foreach (var item in DataService.Connection.GetAll <PCBaseStructureItem>())
                {
                    NWItem deserialized = SerializationService.DeserializeItem(item.ItemObject, storage);
                    PlayerMigrationService.ProcessVersion6_DeflateItemStats(deserialized);
                    ProcessVersion1LightsaberItem(deserialized);
                    item.ItemObject = SerializationService.Serialize(deserialized);
                    DataService.Connection.Update(item);
                    deserialized.Destroy();
                }
                Console.WriteLine("Processed PCBaseStructureItem");

                // PCImpoundedItem
                foreach (var item in DataService.PCImpoundedItem.GetAll())
                {
                    NWItem deserialized = SerializationService.DeserializeItem(item.ItemObject, storage);
                    PlayerMigrationService.ProcessVersion6_DeflateItemStats(deserialized);
                    ProcessVersion1LightsaberItem(deserialized);
                    item.ItemObject = SerializationService.Serialize(deserialized);
                    DataService.Connection.Update(item);
                    deserialized.Destroy();
                }
                Console.WriteLine("Processed PCImpoundedItem");

                // PCMarketListing
                foreach (var item in DataService.PCMarketListing.GetAll())
                {
                    NWItem deserialized = SerializationService.DeserializeItem(item.ItemObject, storage);
                    PlayerMigrationService.ProcessVersion6_DeflateItemStats(deserialized);
                    ProcessVersion1LightsaberItem(deserialized);
                    item.ItemObject = SerializationService.Serialize(deserialized);
                    DataService.Connection.Update(item);
                    deserialized.Destroy();
                }

                Console.WriteLine("Processed PCMarketListing");

                config.ModuleVersion = 1;
                Console.WriteLine("Module migration #1 complete.");
            }

            DataService.SubmitDataChange(config, DatabaseActionType.Update);
        }