Пример #1
0
        public static void ClearPlayerCraftingData(NWPlayer player, bool destroyComponents = false)
        {
            var model = GetPlayerCraftingData(player);

            foreach (var item in model.MainComponents)
            {
                if (!destroyComponents)
                {
                    _.CopyItem(item.Object, player.Object, true);
                }
                item.Destroy();
            }
            foreach (var item in model.SecondaryComponents)
            {
                if (!destroyComponents)
                {
                    _.CopyItem(item.Object, player.Object, true);
                }
                item.Destroy();
            }
            foreach (var item in model.TertiaryComponents)
            {
                if (!destroyComponents)
                {
                    _.CopyItem(item.Object, player.Object, true);
                }
                item.Destroy();
            }
            foreach (var item in model.EnhancementComponents)
            {
                if (!destroyComponents)
                {
                    _.CopyItem(item.Object, player.Object, true);
                }
                item.Destroy();
            }

            if (!string.IsNullOrWhiteSpace(model.SerializedSalvageItem))
            {
                SerializationService.DeserializeItem(model.SerializedSalvageItem, player);
            }

            player.Data.Remove("CRAFTING_MODEL");
            player.DeleteLocalInt("CRAFT_BLUEPRINT_ID");
        }
Пример #2
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));
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        private static void ProcessVersion6ItemChanges(NWPlayer player)
        {
            List <SerializedObjectData> serializedItems = new List <SerializedObjectData>();

            // Start with equipped items.
            foreach (var item in player.EquippedItems)
            {
                ProcessVersion6_DeflateItemStats(item);
                var data = ProcessVersion6LightsaberItem(item);
                if (data.Data != null)
                {
                    serializedItems.Add(data);
                }
            }
            // Next do all inventory items.
            foreach (var item in player.InventoryItems)
            {
                ProcessVersion6_DeflateItemStats(item);
                var data = ProcessVersion6LightsaberItem(item);
                if (data.Data != null)
                {
                    serializedItems.Add(data);
                }
            }

            // Deserialize all items onto the player now.
            foreach (var serialized in serializedItems)
            {
                var item = SerializationService.DeserializeItem(serialized.Data, player);
                BiowareXP2.IPRemoveAllItemProperties(item, DurationType.Permanent);
                foreach (var ip in serialized.ItemPropertiesToAdd)
                {
                    BiowareXP2.IPSafeAddItemProperty(item, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false);
                }
            }
        }
Пример #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);
        }
Пример #6
0
        public static void OnChestOpen(NWPlaceable oChest)
        {
            NWPlayer oPC = (_.GetLastOpenedBy());

            if (!oPC.IsPlayer)
            {
                return;
            }

            if (_.GetActionMode(oPC.Object, _.ACTION_MODE_STEALTH) == _.TRUE)
            {
                _.SetActionMode(oPC.Object, _.ACTION_MODE_STEALTH, _.FALSE);
            }

            string       resref           = oChest.Resref;
            int          chestID          = oChest.GetLocalInt(SearchSiteIDVariableName);
            int          skillRank        = _.GetSkillRank(_.SKILL_SEARCH, oPC.Object);
            int          numberOfSearches = (skillRank / ExtraSearchPerNumberLevels) + 1;
            PCSearchSite searchEntity     = DataService.SingleOrDefault <PCSearchSite>(x => x.PlayerID == oPC.GlobalID && x.SearchSiteID == chestID);
            DateTime     timeLock         = DateTime.UtcNow;

            if (numberOfSearches <= 0)
            {
                numberOfSearches = 1;
            }

            if (searchEntity != null)
            {
                timeLock = searchEntity.UnlockDateTime;
            }

            if (resref == SearchSiteCopyResref)
            {
                oChest.IsUseable = false;
            }

            QuestService.SpawnQuestItems(oChest, oPC);

            if (timeLock < DateTime.UtcNow || searchEntity == null)
            {
                int dc = oChest.GetLocalInt(SearchSiteDCVariableName);

                for (int search = 1; search <= numberOfSearches; search++)
                {
                    RunSearchCycle(oPC, oChest, dc);
                    dc += RandomService.Random(3) + 1;
                }

                SaveChestInventory(oPC, oChest, false);
            }
            else
            {
                var searchItems = DataService.Where <PCSearchSiteItem>(x => x.PlayerID == oPC.GlobalID && x.SearchSiteID == searchEntity.SearchSiteID).ToList();
                foreach (PCSearchSiteItem item in searchItems)
                {
                    NWItem oItem = SerializationService.DeserializeItem(item.SearchItem, oChest);

                    // Prevent item duplication in containers
                    if (oItem.HasInventory)
                    {
                        foreach (NWItem containerItem in oItem.InventoryItems)
                        {
                            containerItem.Destroy();
                        }
                    }
                }
            }
        }