コード例 #1
0
        void RestoreExteriorPositionHandler(DaggerfallLoot loot, LootContainerData_v1 data, WorldContext lootContext)
        {
            // If loot context matches serialized world context then loot was saved after floating y change
            // Need to get relative difference between current and serialized world compensation to get actual y position
            if (lootContext == data.worldContext)
            {
                float diffY = GameManager.Instance.StreamingWorld.WorldCompensation.y - data.worldCompensation.y;
                loot.transform.position = data.currentPosition + new Vector3(0, diffY, 0);
                return;
            }

            // Otherwise we migrate a legacy exterior position by adjusting for world compensation
            loot.transform.position = data.currentPosition + GameManager.Instance.StreamingWorld.WorldCompensation;
        }
コード例 #2
0
        public void RestoreSaveData(object dataIn)
        {
            if (!loot)
            {
                return;
            }

            LootContainerData_v1 data = (LootContainerData_v1)dataIn;

            if (data.loadID != LoadID)
            {
                return;
            }

            DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>();

            // Restore position
            loot.transform.position = data.currentPosition;

            // Restore billboard appearance if present
            if (billboard)
            {
                billboard.SetMaterial(data.textureArchive, data.textureRecord);

                // Setup custom material if available
                if (TextureReplacement.CustomTextureExist(data.textureArchive, data.textureRecord))
                {
                    TextureReplacement.SetBillboardCustomMaterial(billboard.gameObject, data.textureArchive, data.textureRecord);
                }
            }

            // Restore items
            loot.Items.DeserializeItems(data.items);

            // Restore other data
            loot.ContainerType  = data.containerType;
            loot.ContainerImage = data.containerImage;
            loot.LootTableKey   = data.lootTableKey;
            loot.TextureArchive = data.textureArchive;
            loot.TextureRecord  = data.textureRecord;
            loot.playerOwned    = data.playerOwned;
            loot.customDrop     = data.customDrop;
            loot.name           = loot.ContainerType.ToString();

            // Remove loot container if empty
            if (loot.Items.Count == 0)
            {
                GameObjectHelper.RemoveLootContainer(loot);
            }
        }
        public object GetSaveData()
        {
            if (!loot)
                return null;

            // Create save data
            LootContainerData_v1 data = new LootContainerData_v1();
            data.loadID = LoadID;
            data.containerType = loot.ContainerType;
            data.containerImage = loot.ContainerImage;
            data.currentPosition = loot.transform.position;
            data.textureArchive = loot.TextureArchive;
            data.textureRecord = loot.TextureRecord;
            data.lootTableKey = loot.LootTableKey;
            data.playerOwned = loot.playerOwned;
            data.customDrop = loot.customDrop;
            data.items = loot.Items.SerializeItems();

            return data;
        }
コード例 #4
0
        void RestoreInteriorPositionHandler(DaggerfallLoot loot, LootContainerData_v1 data, WorldContext lootContext)
        {
            // If loot context matches serialized world context then loot was saved after floating y change
            // Can simply restore local position relative to parent interior
            if (lootContext == data.worldContext)
            {
                loot.transform.localPosition = data.localPosition;
                return;
            }

            // Otherwise we need to migrate a legacy interior position to floating y
            if (GameManager.Instance.PlayerEnterExit.LastInteriorStartFlag)
            {
                // Loading interior uses serialized absolute position (as interior also serialized this way)
                loot.transform.position = data.currentPosition;
            }
            else
            {
                // Transition to interior must offset serialized absolute position by floating y compensation
                loot.transform.position = data.currentPosition + GameManager.Instance.StreamingWorld.WorldCompensation;
            }
        }
コード例 #5
0
        public object GetSaveData()
        {
            if (!loot)
            {
                return(null);
            }

            // Create save data
            LootContainerData_v1 data = new LootContainerData_v1();

            data.loadID          = LoadID;
            data.containerType   = loot.ContainerType;
            data.containerImage  = loot.ContainerImage;
            data.currentPosition = loot.transform.position;
            data.textureArchive  = loot.TextureArchive;
            data.textureRecord   = loot.TextureRecord;
            data.lootTableKey    = loot.LootTableKey;
            data.playerOwned     = loot.playerOwned;
            data.customDrop      = loot.customDrop;
            data.items           = loot.Items.SerializeItems();

            return(data);
        }
コード例 #6
0
        public void RestoreSaveData(object dataIn)
        {
            if (!loot)
            {
                return;
            }

            LootContainerData_v1 data = (LootContainerData_v1)dataIn;

            if (data.loadID != LoadID)
            {
                return;
            }

            // Restore billboard only if this is a billboard-based loot container
            if (loot.ContainerType == LootContainerTypes.RandomTreasure ||
                loot.ContainerType == LootContainerTypes.CorpseMarker ||
                loot.ContainerType == LootContainerTypes.DroppedLoot)
            {
                DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>();

                // Interiors and exteriors need special handling to ensure loot is always placed correctly for pre and post floating y saves
                // Dungeons are not involved with floating y and don't need any changes
                WorldContext lootContext = GetLootWorldContext(loot);
                if (lootContext == WorldContext.Interior)
                {
                    RestoreInteriorPositionHandler(loot, data, lootContext);
                }
                else if (lootContext == WorldContext.Exterior)
                {
                    RestoreExteriorPositionHandler(loot, data, lootContext);
                }
                else
                {
                    loot.transform.position = data.currentPosition;
                }

                // Restore appearance
                if (MeshReplacement.SwapCustomFlatGameobject(data.textureArchive, data.textureRecord, loot.transform, Vector3.zero, lootContext == WorldContext.Dungeon))
                {
                    // Use imported model instead of billboard
                    if (billboard)
                    {
                        Destroy(billboard);
                    }
                    Destroy(GetComponent <MeshRenderer>());
                }
                else if (billboard)
                {
                    // Restore billboard appearance if present
                    billboard.SetMaterial(data.textureArchive, data.textureRecord);
                }
            }

            // Restore items
            loot.Items.DeserializeItems(data.items);

            // Restore other data
            loot.ContainerType  = data.containerType;
            loot.ContainerImage = data.containerImage;
            loot.TextureArchive = data.textureArchive;
            loot.TextureRecord  = data.textureRecord;
            loot.stockedDate    = data.stockedDate;
            loot.playerOwned    = data.playerOwned;
            loot.customDrop     = data.customDrop;
            loot.entityName     = data.entityName;
            loot.isEnemyClass   = data.isEnemyClass;

            // Remove loot container if empty
            if (loot.Items.Count == 0)
            {
                GameObjectHelper.RemoveLootContainer(loot);
            }
        }
コード例 #7
0
        public void RestoreSaveData(object dataIn)
        {
            if (!loot)
            {
                return;
            }

            LootContainerData_v1 data = (LootContainerData_v1)dataIn;

            if (data.loadID != LoadID)
            {
                return;
            }

            // Restore billboard only if this is a billboard-based loot container
            if (loot.ContainerType == LootContainerTypes.RandomTreasure ||
                loot.ContainerType == LootContainerTypes.CorpseMarker ||
                loot.ContainerType == LootContainerTypes.DroppedLoot)
            {
                DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>();

                // Restore position
                loot.transform.position = data.currentPosition;

                // Restore appearance
                if (MeshReplacement.ImportCustomFlatGameobject(data.textureArchive, data.textureRecord, Vector3.zero, loot.transform))
                {
                    // Use imported model instead of billboard
                    if (billboard)
                    {
                        Destroy(billboard);
                    }
                    Destroy(GetComponent <MeshRenderer>());
                }
                else if (billboard)
                {
                    // Restore billboard appearance if present
                    billboard.SetMaterial(data.textureArchive, data.textureRecord);
                }
            }

            // Restore items
            loot.Items.DeserializeItems(data.items);

            // Restore other data
            loot.ContainerType  = data.containerType;
            loot.ContainerImage = data.containerImage;
            loot.TextureArchive = data.textureArchive;
            loot.TextureRecord  = data.textureRecord;
            loot.stockedDate    = data.stockedDate;
            loot.playerOwned    = data.playerOwned;
            loot.customDrop     = data.customDrop;
            loot.entityName     = data.entityName;
            loot.isEnemyClass   = data.isEnemyClass;

            // Remove loot container if empty
            if (loot.Items.Count == 0)
            {
                GameObjectHelper.RemoveLootContainer(loot);
            }
        }
コード例 #8
0
        void RestoreLootContainerData(LootContainerData_v1[] lootContainers)
        {
            if (lootContainers == null || lootContainers.Length == 0)
                return;

            for (int i = 0; i < lootContainers.Length; i++)
            {
                // Skip null containers
                if (lootContainers[i] == null)
                    continue;

                // Restore loot containers
                ulong key = lootContainers[i].loadID;
                if (serializableLootContainers.ContainsKey(key))
                {
                    // Apply to known loot container that is part of scene build
                    serializableLootContainers[key].RestoreSaveData(lootContainers[i]);
                }
                else
                {
                    // Add custom drop containers back to scene (e.g. dropped loot, slain foes)
                    if (lootContainers[i].customDrop)
                    {
                        DaggerfallLoot customLootContainer = GameObjectHelper.CreateDroppedLootContainer(GameManager.Instance.PlayerObject, key);
                        SerializableLootContainer serializableLootContainer = customLootContainer.GetComponent<SerializableLootContainer>();
                        if (serializableLootContainer)
                        {
                            serializableLootContainer.RestoreSaveData(lootContainers[i]);
                        }
                    }
                }
            }
        }