示例#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");
        }
        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);
                }
            }
        }
示例#3
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);
        }
示例#4
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();
                        }
                    }
                }
            }
        }