public object GetSaveData()
        {
            if (!enemy)
            {
                return(null);
            }

            // Get entity behaviour
            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();

            if (!entityBehaviour)
            {
                return(null);
            }

            // Create save data
            EnemyEntity          entity      = entityBehaviour.Entity as EnemyEntity;
            EnemyMotor           motor       = enemy.GetComponent <EnemyMotor>();
            EnemySenses          senses      = enemy.GetComponent <EnemySenses>();
            DaggerfallMobileUnit mobileEnemy = enemy.GetComponentInChildren <DaggerfallMobileUnit>();
            EnemyData_v1         data        = new EnemyData_v1();

            data.loadID               = LoadID;
            data.gameObjectName       = entityBehaviour.gameObject.name;
            data.currentPosition      = enemy.transform.position;
            data.localPosition        = enemy.transform.localPosition;
            data.currentRotation      = enemy.transform.rotation;
            data.worldContext         = entity.WorldContext;
            data.worldCompensation    = GameManager.Instance.StreamingWorld.WorldCompensation;
            data.entityType           = entity.EntityType;
            data.careerName           = entity.Career.Name;
            data.careerIndex          = entity.CareerIndex;
            data.startingHealth       = entity.MaxHealth;
            data.currentHealth        = entity.CurrentHealth;
            data.currentFatigue       = entity.CurrentFatigue;
            data.currentMagicka       = entity.CurrentMagicka;
            data.isHostile            = motor.IsHostile;
            data.hasEncounteredPlayer = senses.HasEncounteredPlayer;
            data.isDead               = (entity.CurrentHealth <= 0) ? true : false;
            data.questSpawn           = enemy.QuestSpawn;
            data.mobileGender         = mobileEnemy.Summary.Enemy.Gender;
            data.items                   = entity.Items.SerializeItems();
            data.equipTable              = entity.ItemEquipTable.SerializeEquipTable();
            data.instancedEffectBundles  = GetComponent <EntityEffectManager>().GetInstancedBundlesSaveData();
            data.alliedToPlayer          = mobileEnemy.Summary.Enemy.Team == MobileTeams.PlayerAlly;
            data.questFoeSpellQueueIndex = entity.QuestFoeSpellQueueIndex;
            data.questFoeItemQueueIndex  = entity.QuestFoeItemQueueIndex;
            data.wabbajackActive         = entity.WabbajackActive;
            data.team = (int)entity.Team + 1;

            // Add quest resource data if present
            QuestResourceBehaviour questResourceBehaviour = GetComponent <QuestResourceBehaviour>();

            if (questResourceBehaviour)
            {
                data.questResource = questResourceBehaviour.GetSaveData();
            }

            return(data);
        }
        public object GetSaveData()
        {
            if (!enemy)
                return null;

            // Get entity behaviour
            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent<DaggerfallEntityBehaviour>();
            if (!entityBehaviour)
                return null;

            // Create save data
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;
            EnemyMotor motor = enemy.GetComponent<EnemyMotor>();
            EnemyData_v1 data = new EnemyData_v1();
            data.loadID = LoadID;
            data.currentPosition = enemy.transform.position;
            data.currentRotation = enemy.transform.rotation;
            data.entityType = entity.EntityType;
            data.careerName = entity.Career.Name;
            data.careerIndex = entity.CareerIndex;
            data.startingHealth = entity.MaxHealth;
            data.currentHealth = entity.CurrentHealth;
            data.currentFatigue = entity.CurrentFatigue;
            data.currentMagicka = entity.CurrentMagicka;
            data.isHostile = motor.IsHostile;
            data.isDead = (entity.CurrentHealth <= 0) ? true : false;

            return data;
        }
        public object GetSaveData()
        {
            if (!enemy)
            {
                return(null);
            }

            // Get entity behaviour
            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();

            if (!entityBehaviour)
            {
                return(null);
            }

            // Create save data
            EnemyEntity  entity = entityBehaviour.Entity as EnemyEntity;
            EnemyMotor   motor  = enemy.GetComponent <EnemyMotor>();
            EnemyData_v1 data   = new EnemyData_v1();

            data.loadID          = LoadID;
            data.currentPosition = enemy.transform.position;
            data.currentRotation = enemy.transform.rotation;
            data.entityType      = entity.EntityType;
            data.careerName      = entity.Career.Name;
            data.careerIndex     = entity.CareerIndex;
            data.startingHealth  = entity.MaxHealth;
            data.currentHealth   = entity.CurrentHealth;
            data.currentFatigue  = entity.CurrentFatigue;
            data.currentMagicka  = entity.CurrentMagicka;
            data.isHostile       = motor.IsHostile;
            data.isDead          = (entity.CurrentHealth <= 0) ? true : false;

            return(data);
        }
Beispiel #4
0
        public object GetSaveData()
        {
            if (!enemy)
            {
                return(null);
            }

            // Get entity behaviour
            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();

            if (!entityBehaviour)
            {
                return(null);
            }

            // Create save data
            EnemyEntity          entity      = entityBehaviour.Entity as EnemyEntity;
            EnemyMotor           motor       = enemy.GetComponent <EnemyMotor>();
            EnemySenses          senses      = enemy.GetComponent <EnemySenses>();
            DaggerfallMobileUnit mobileEnemy = enemy.GetComponentInChildren <DaggerfallMobileUnit>();
            EnemyData_v1         data        = new EnemyData_v1();

            data.loadID               = LoadID;
            data.gameObjectName       = entityBehaviour.gameObject.name;
            data.currentPosition      = enemy.transform.position;
            data.currentRotation      = enemy.transform.rotation;
            data.entityType           = entity.EntityType;
            data.careerName           = entity.Career.Name;
            data.careerIndex          = entity.CareerIndex;
            data.startingHealth       = entity.MaxHealth;
            data.currentHealth        = entity.CurrentHealth;
            data.currentFatigue       = entity.CurrentFatigue;
            data.currentMagicka       = entity.CurrentMagicka;
            data.isHostile            = motor.IsHostile;
            data.hasEncounteredPlayer = senses.HasEncounteredPlayer;
            data.isDead               = (entity.CurrentHealth <= 0) ? true : false;
            data.questSpawn           = enemy.QuestSpawn;
            data.mobileGender         = mobileEnemy.Summary.Enemy.Gender;
            data.items      = entity.Items.SerializeItems();
            data.equipTable = entity.ItemEquipTable.SerializeEquipTable();

            // Add quest resource data if present
            QuestResourceBehaviour questResourceBehaviour = GetComponent <QuestResourceBehaviour>();

            if (questResourceBehaviour)
            {
                data.questResource = questResourceBehaviour.GetSaveData();
            }

            return(data);
        }
        void RestoreExteriorPositionHandler(DaggerfallEnemy enemy, EnemyData_v1 data, WorldContext enemyContext)
        {
            // If enemy context matches serialized world context then enemy was saved after floating y change
            // Need to get relative difference between current and serialized world compensation to get actual y position
            if (enemyContext == data.worldContext)
            {
                float diffY = GameManager.Instance.StreamingWorld.WorldCompensation.y - data.worldCompensation.y;
                enemy.transform.position = data.currentPosition + new Vector3(0, diffY, 0);
                return;
            }

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

            EnemyData_v1 data = (EnemyData_v1)dataIn;

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

            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();
            EnemySenses senses = enemy.GetComponent <EnemySenses>();
            EnemyMotor  motor  = enemy.GetComponent <EnemyMotor>();
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;

            // Quiesce entity during state restore
            entity.Quiesce = true;

            // Restore enemy career or class if different
            if (entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex)
            {
                SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>();
                setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.isHostile);
                setupEnemy.AlignToGround();
            }

            // Restore enemy position
            enemy.transform.position    = data.currentPosition;
            enemy.transform.rotation    = data.currentRotation;
            entity.MaxHealth            = data.startingHealth;
            entity.CurrentHealth        = data.currentHealth;
            entity.CurrentFatigue       = data.currentFatigue;
            entity.CurrentMagicka       = data.currentMagicka;
            motor.IsHostile             = data.isHostile;
            senses.HasEncounteredPlayer = true;

            // Disable dead enemies
            if (data.isDead)
            {
                entityBehaviour.gameObject.SetActive(false);
            }

            // Resume entity
            entity.Quiesce = false;
        }
        public void RestoreSaveData(object dataIn)
        {
            if (!enemy)
            {
                return;
            }

            EnemyData_v1 data = (EnemyData_v1)dataIn;

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

            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();
            EnemySenses senses = enemy.GetComponent <EnemySenses>();
            EnemyMotor  motor  = enemy.GetComponent <EnemyMotor>();
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;

            // Restore enemy career or class if different
            if (entity == null || entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex)
            {
                SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>();
                setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.mobileGender, data.isHostile, alliedToPlayer: data.alliedToPlayer);
                setupEnemy.AlignToGround();

                if (entity == null)
                {
                    entity = entityBehaviour.Entity as EnemyEntity;
                }
            }

            // Quiesce entity during state restore
            entity.Quiesce = true;

            // Restore enemy data
            entityBehaviour.gameObject.name = data.gameObjectName;
            enemy.transform.rotation        = data.currentRotation;
            entity.QuestFoeSpellQueueIndex  = data.questFoeSpellQueueIndex;
            entity.QuestFoeItemQueueIndex   = data.questFoeItemQueueIndex;
            entity.WabbajackActive          = data.wabbajackActive;
            entity.Items.DeserializeItems(data.items);
            entity.ItemEquipTable.DeserializeEquipTable(data.equipTable, entity.Items);
            entity.MaxHealth = data.startingHealth;
            entity.SetHealth(data.currentHealth, true);
            entity.SetFatigue(data.currentFatigue, true);
            entity.SetMagicka(data.currentMagicka, true);
            int team = data.team;

            if (team > 0)   // Added 1 to made backwards compatible. 0 = no team saved
            {
                entity.Team = (MobileTeams)(team - 1);
            }
            motor.IsHostile             = data.isHostile;
            senses.HasEncounteredPlayer = data.hasEncounteredPlayer;

            // Restore enemy position and migrate to floating y support for exteriors
            // Interiors seem to be working fine at this stage with any additional support
            // Dungeons are not involved with floating y and don't need any changes
            WorldContext enemyContext = GetEnemyWorldContext(enemy);

            if (enemyContext == WorldContext.Exterior)
            {
                RestoreExteriorPositionHandler(enemy, data, enemyContext);
            }
            else
            {
                // Everything else
                enemy.transform.position = data.currentPosition;
            }

            // Disable dead enemies
            if (data.isDead)
            {
                entityBehaviour.gameObject.SetActive(false);
            }

            // Restore quest resource link
            enemy.QuestSpawn = data.questSpawn;
            if (enemy.QuestSpawn)
            {
                // Add QuestResourceBehaviour to GameObject
                QuestResourceBehaviour questResourceBehaviour = entityBehaviour.gameObject.AddComponent <QuestResourceBehaviour>();
                questResourceBehaviour.RestoreSaveData(data.questResource);

                // Destroy QuestResourceBehaviour if no actual quest properties are restored from save
                if (questResourceBehaviour.QuestUID == 0 || questResourceBehaviour.TargetSymbol == null)
                {
                    enemy.QuestSpawn = false;
                    Destroy(questResourceBehaviour);
                }
            }

            // Restore instanced effect bundles
            GetComponent <EntityEffectManager>().RestoreInstancedBundleSaveData(data.instancedEffectBundles);

            // Resume entity
            entity.Quiesce = false;
        }
Beispiel #8
0
        public void RestoreSaveData(object dataIn)
        {
            if (!enemy)
            {
                return;
            }

            EnemyData_v1 data = (EnemyData_v1)dataIn;

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

            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();
            EnemySenses senses = enemy.GetComponent <EnemySenses>();
            EnemyMotor  motor  = enemy.GetComponent <EnemyMotor>();
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;

            // Restore enemy career or class if different
            if (entity == null || entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex)
            {
                SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>();
                setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.mobileGender, data.isHostile);
                setupEnemy.AlignToGround();

                if (entity == null)
                {
                    entity = entityBehaviour.Entity as EnemyEntity;
                }
            }

            // Quiesce entity during state restore
            entity.Quiesce = true;

            // Restore enemy data
            entityBehaviour.gameObject.name = data.gameObjectName;
            enemy.transform.position        = data.currentPosition;
            enemy.transform.rotation        = data.currentRotation;
            entity.Items.DeserializeItems(data.items);
            entity.ItemEquipTable.DeserializeEquipTable(data.equipTable, entity.Items);
            entity.MaxHealth            = data.startingHealth;
            entity.CurrentHealth        = data.currentHealth;
            entity.CurrentFatigue       = data.currentFatigue;
            entity.CurrentMagicka       = data.currentMagicka;
            motor.IsHostile             = data.isHostile;
            senses.HasEncounteredPlayer = data.hasEncounteredPlayer;

            // Disable dead enemies
            if (data.isDead)
            {
                entityBehaviour.gameObject.SetActive(false);
            }

            // Restore quest resource link
            enemy.QuestSpawn = data.questSpawn;
            if (enemy.QuestSpawn)
            {
                // Add QuestResourceBehaviour to GameObject
                QuestResourceBehaviour questResourceBehaviour = entityBehaviour.gameObject.AddComponent <QuestResourceBehaviour>();
                questResourceBehaviour.RestoreSaveData(data.questResource);
            }

            // Resume entity
            entity.Quiesce = false;
        }
        void RestoreEnemyData(EnemyData_v1[] enemies)
        {
            if (enemies == null || enemies.Length == 0)
                return;

            for (int i = 0; i <enemies.Length; i++)
            {
                long key = enemies[i].loadID;
                if (serializableEnemies.ContainsKey(key))
                {
                    serializableEnemies[key].RestoreSaveData(enemies[i]);
                }
            }
        }
        public void RestoreSaveData(object dataIn)
        {
            if (!enemy)
            {
                return;
            }

            EnemyData_v1 data = (EnemyData_v1)dataIn;

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

            DaggerfallEntityBehaviour entityBehaviour = enemy.GetComponent <DaggerfallEntityBehaviour>();
            EnemySenses senses = enemy.GetComponent <EnemySenses>();
            EnemyMotor  motor  = enemy.GetComponent <EnemyMotor>();
            EnemyEntity entity = entityBehaviour.Entity as EnemyEntity;

            // Restore enemy career or class if different
            if (entity == null || entity.EntityType != data.entityType || entity.CareerIndex != data.careerIndex)
            {
                SetupDemoEnemy setupEnemy = enemy.GetComponent <SetupDemoEnemy>();
                setupEnemy.ApplyEnemySettings(data.entityType, data.careerIndex, data.mobileGender, data.isHostile);
                setupEnemy.AlignToGround();

                if (entity == null)
                {
                    entity = entityBehaviour.Entity as EnemyEntity;
                }
            }

            // Quiesce entity during state restore
            entity.Quiesce = true;

            // Restore enemy data
            entityBehaviour.gameObject.name = data.gameObjectName;
            enemy.transform.rotation        = data.currentRotation;
            entity.Items.DeserializeItems(data.items);
            entity.ItemEquipTable.DeserializeEquipTable(data.equipTable, entity.Items);
            entity.MaxHealth            = data.startingHealth;
            entity.CurrentHealth        = data.currentHealth;
            entity.CurrentFatigue       = data.currentFatigue;
            entity.CurrentMagicka       = data.currentMagicka;
            motor.IsHostile             = data.isHostile;
            senses.HasEncounteredPlayer = data.hasEncounteredPlayer;

            // Restore enemy position and migrate to floating y support for exteriors
            // Interiors seem to be working fine at this stage with any additional support
            // Dungeons are not involved with floating y and don't need any changes
            WorldContext enemyContext = GetEnemyWorldContext(enemy);

            if (enemyContext == WorldContext.Exterior)
            {
                RestoreExteriorPositionHandler(enemy, data, enemyContext);
            }
            else
            {
                // Everything else
                enemy.transform.position = data.currentPosition;
            }

            // Disable dead enemies
            if (data.isDead)
            {
                entityBehaviour.gameObject.SetActive(false);
            }

            // Restore quest resource link
            enemy.QuestSpawn = data.questSpawn;
            if (enemy.QuestSpawn)
            {
                // Add QuestResourceBehaviour to GameObject
                QuestResourceBehaviour questResourceBehaviour = entityBehaviour.gameObject.AddComponent <QuestResourceBehaviour>();
                questResourceBehaviour.RestoreSaveData(data.questResource);
            }

            // Resume entity
            entity.Quiesce = false;
        }