Exemplo n.º 1
0
        private static void AddEnemy(
            DFBlock.RdbObject obj,
            MobileTypes type,
            Transform parent = null,
            DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold)
        {
            // Get default reaction
            MobileReactions reaction = MobileReactions.Hostile;

            if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive)
            {
                reaction = MobileReactions.Passive;
            }

            // Just setup demo enemies at this time
            string         name       = string.Format("DaggerfallEnemy [{0}]", type.ToString());
            Vector3        position   = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;
            GameObject     go         = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, parent, position);
            SetupDemoEnemy setupEnemy = go.GetComponent <SetupDemoEnemy>();

            if (setupEnemy != null)
            {
                // Configure enemy
                setupEnemy.ApplyEnemySettings(type, reaction);

                // Align non-flying units with ground
                DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild();
                if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying)
                {
                    GameObjectHelper.AlignControllerToGround(go.GetComponent <CharacterController>());
                }
            }
        }
        /// <summary>
        /// Sets new enemy type.
        /// </summary>
        /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param>
        /// <param name="enemyType">Enemy type.</param>
        public void SetEnemy(DaggerfallUnity dfUnity, MobileEnemy enemy, MobileReactions reaction)
        {
            // Initial enemy settings
            summary.Enemy           = enemy;
            summary.EnemyState      = MobileStates.Move;
            summary.Enemy.Reactions = reaction;

            // Load enemy content
            int archive = GetTextureArchive();

            if (TextureReplacement.CustomTextureExist(archive, TextureReplacement.enemyDefaultRecord, TextureReplacement.enemyDefaultFrame))
            {
                summary.CustomMaterial.isCustom = true;
            }
            else
            {
                summary.CustomMaterial.isCustom = false;
            }
            CacheRecordSizesAndFrames(dfUnity, archive);
            AssignMeshAndMaterial(dfUnity, archive);

            // Apply enemy state and update orientation
            lastOrientation = -1;
            ApplyEnemyState();

            // Raise setup flag
            summary.IsSetup = true;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Change enemy settings and configure in a single call.
 /// </summary>
 /// <param name="enemyType">Enemy type.</param>
 public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender)
 {
     EnemyType     = enemyType;
     EnemyReaction = enemyReaction;
     Gender        = gender;
     ApplyEnemySettings();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Change enemy settings and configure in a single call.
 /// </summary>
 /// <param name="enemyType">Enemy type.</param>
 public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender, byte classicSpawnDistanceType = 0)
 {
     EnemyType                = enemyType;
     EnemyReaction            = enemyReaction;
     ClassicSpawnDistanceType = classicSpawnDistanceType;
     ApplyEnemySettings(gender);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Change enemy settings and configure in a single call.
 /// </summary>
 /// <param name="enemyType">Enemy type.</param>
 public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender, byte classicSpawnDistanceType = 0, bool alliedToPlayer = false)
 {
     EnemyType                = enemyType;
     EnemyReaction            = enemyReaction;
     ClassicSpawnDistanceType = classicSpawnDistanceType;
     AlliedToPlayer           = alliedToPlayer;
     ApplyEnemySettings(gender);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Sets enemy data for setup.
        /// </summary>
        /// <param name="dfUnity">Current instance of Daggerfall Unity.</param>
        /// <param name="enemy">Basic properties of this enemy.</param>
        /// <param name="reaction">Reaction setting for this enemy.</param>
        /// <param name="classicSpawnDistanceType">An index that defines spawn distance type.</param>
        public void SetEnemy(DaggerfallUnity dfUnity, MobileEnemy enemy, MobileReactions reaction, byte classicSpawnDistanceType)
        {
            enemy.Reactions = reaction;

            Enemy      = enemy;
            EnemyState = MobileStates.Move;
            ClassicSpawnDistanceType = classicSpawnDistanceType;

            ApplyEnemy(dfUnity);

            IsSetup = true;
        }
        /// <summary>
        /// Sets new enemy type.
        /// </summary>
        /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param>
        /// <param name="enemyType">Enemy type.</param>
        public void SetEnemy(DaggerfallUnity dfUnity, MobileEnemy enemy, MobileReactions reaction)
        {
            // Initial enemy settings
            summary.Enemy           = enemy;
            summary.EnemyState      = MobileStates.Idle;
            summary.Enemy.Reactions = reaction;

            // Load enemy content
            int archive = GetTextureArchive();

            CacheRecordSizesAndFrames(dfUnity, archive);
            AssignMeshAndMaterial(dfUnity, archive);
            ApplyEnemyState();
        }
        /// <summary>
        /// Sets new enemy type.
        /// </summary>
        /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param>
        /// <param name="enemyType">Enemy type.</param>
        public void SetEnemy(DaggerfallUnity dfUnity, MobileEnemy enemy, MobileReactions reaction)
        {
            // Initial enemy settings
            summary.Enemy           = enemy;
            summary.EnemyState      = MobileStates.Move;
            summary.Enemy.Reactions = reaction;

            // Load enemy content
            int archive = GetTextureArchive();

            CacheRecordSizesAndFrames(dfUnity, archive);
            AssignMeshAndMaterial(dfUnity, archive);

            // Apply enemy state and update orientation
            lastOrientation = -1;
            ApplyEnemyState();

            // Raise setup flag
            summary.IsSetup = true;
        }
        /// <summary>
        /// Change enemy settings and configure in a single call.
        /// </summary>
        public void ApplyEnemySettings(EntityTypes entityType, int careerIndex, bool isHostile = true)
        {
            // Get mobile type based on entity type and career index
            MobileTypes mobileType;

            if (entityType == EntityTypes.EnemyMonster)
            {
                mobileType = (MobileTypes)careerIndex;
            }
            else if (entityType == EntityTypes.EnemyClass)
            {
                mobileType = (MobileTypes)(careerIndex + 128);
            }
            else
            {
                return;
            }

            MobileReactions enemyReaction = (isHostile) ? MobileReactions.Hostile : MobileReactions.Passive;

            ApplyEnemySettings(mobileType, enemyReaction);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Change enemy settings and configure in a single call.
        /// </summary>
        public void ApplyEnemySettings(EntityTypes entityType, int careerIndex, bool isHostile = true)
        {
            // Get mobile type based on entity type and career index
            MobileTypes mobileType;

            if (entityType == EntityTypes.EnemyMonster)
            {
                mobileType = (MobileTypes)careerIndex;
            }
            else if (entityType == EntityTypes.EnemyClass)
            {
                mobileType = (MobileTypes)(careerIndex + 128);
            }
            else
            {
                return;
            }

            MobileReactions enemyReaction = (isHostile) ? MobileReactions.Hostile : MobileReactions.Passive;
            MobileGender    enemyGender   = MobileGender.Unspecified; // TODO: Gender should be included in and read from save file

            ApplyEnemySettings(mobileType, enemyReaction, enemyGender);
        }
Exemplo n.º 11
0
        private void AddEnemy(DFBlock.RdbObject obj, MobileTypes type)
        {
            // Get default reaction
            MobileReactions reaction = MobileReactions.Hostile;

            if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive)
            {
                reaction = MobileReactions.Passive;
            }

            // Spawn enemy gameobject
            GameObject go = GameObjectHelper.CreateDaggerfallEnemyGameObject(type, enemiesNode.transform, reaction);

            if (go == null)
            {
                return;
            }

            // Set transform
            Vector3 enemyPosition = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;

            go.transform.position = enemyPosition;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Change enemy settings and configure in a single call.
        /// </summary>
        public void ApplyEnemySettings(EntityTypes entityType, int careerIndex, MobileGender gender, bool isHostile = true, bool alliedToPlayer = false)
        {
            // Get mobile type based on entity type and career index
            MobileTypes mobileType;

            if (entityType == EntityTypes.EnemyMonster)
            {
                mobileType = (MobileTypes)careerIndex;
            }
            else if (entityType == EntityTypes.EnemyClass)
            {
                mobileType = (MobileTypes)(careerIndex + 128);
            }
            else
            {
                return;
            }

            MobileReactions enemyReaction = (isHostile) ? MobileReactions.Hostile : MobileReactions.Passive;
            MobileGender    enemyGender   = gender;

            ApplyEnemySettings(mobileType, enemyReaction, enemyGender, alliedToPlayer: alliedToPlayer);
        }
Exemplo n.º 13
0
        public static GameObject CreateDaggerfallEnemyGameObject(MobileTypes type, Transform parent, MobileReactions reaction)
        {
            DaggerfallUnity dfUnity = DaggerfallUnity.Instance;

            // Ensure enemy dict is loaded
            if (enemyDict == null)
            {
                enemyDict = EnemyBasics.GetEnemyDict();
            }

            GameObject go = new GameObject(string.Format("DaggerfallEnemy [{0}]", type.ToString()));

            if (parent)
            {
                go.transform.parent = parent;
            }
            go.transform.forward = Vector3.forward;

            // Add custom tag and script
            go.tag = dfUnity.Option_EnemyTag;
#if UNITY_EDITOR
            if (dfUnity.Option_CustomEnemyScript != null)
            {
                go.AddComponent(dfUnity.Option_CustomEnemyScript.GetClass());
            }
#endif

            // Add child object for enemy billboard
            GameObject mobileObject = new GameObject("DaggerfallMobileUnit");
            mobileObject.transform.parent = go.transform;

            // Add mobile enemy
            Vector2 size = Vector2.one;
            DaggerfallMobileUnit dfMobile = mobileObject.AddComponent <DaggerfallMobileUnit>();
            dfMobile.SetEnemy(dfUnity, enemyDict[(int)type], reaction);
            size = dfMobile.Summary.RecordSizes[0];

            // Add character controller
            if (dfUnity.Option_EnemyCharacterController || dfUnity.Option_EnemyExampleAI)
            {
                CharacterController controller = go.AddComponent <CharacterController>();
                controller.radius     = dfUnity.Option_EnemyRadius;
                controller.height     = size.y;
                controller.slopeLimit = dfUnity.Option_EnemySlopeLimit;
                controller.stepOffset = dfUnity.Option_EnemyStepOffset;

                // Reduce height of flying creatures as their wing animation makes them taller than desired
                // This helps them get through doors while aiming for player eye height
                if (dfMobile.Summary.Enemy.Behaviour == MobileBehaviour.Flying)
                {
                    controller.height /= 2f;
                }

                // Limit maximum height to ensure controller can fit through doors
                // For some reason Unity 4.5 doesn't let you set SkinWidth from code >.<
                if (controller.height > 1.9f)
                {
                    controller.height = 1.9f;
                }
            }

            // Add rigidbody
            if (dfUnity.Option_EnemyRigidbody)
            {
                Rigidbody rigidbody = go.AddComponent <Rigidbody>();
                rigidbody.useGravity  = dfUnity.Option_EnemyUseGravity;
                rigidbody.isKinematic = dfUnity.Option_EnemyIsKinematic;
            }

            // Add capsule collider
            if (dfUnity.Option_EnemyCapsuleCollider)
            {
                CapsuleCollider collider = go.AddComponent <CapsuleCollider>();
                collider.radius = dfUnity.Option_EnemyRadius;
                collider.height = size.y;
            }

            // Add navmesh agent
            if (dfUnity.Option_EnemyNavMeshAgent)
            {
                NavMeshAgent agent = go.AddComponent <NavMeshAgent>();
                agent.radius     = dfUnity.Option_EnemyRadius;
                agent.height     = size.y;
                agent.baseOffset = size.y * 0.5f;
            }

            // Add example AI
            if (dfUnity.Option_EnemyExampleAI)
            {
                // EnemyMotor will also add other required components
                go.AddComponent <Demo.EnemyMotor>();

                // Set sounds
                Demo.EnemySounds enemySounds = go.GetComponent <Demo.EnemySounds>();
                if (enemySounds)
                {
                    enemySounds.MoveSound   = (SoundClips)dfMobile.Summary.Enemy.MoveSound;
                    enemySounds.BarkSound   = (SoundClips)dfMobile.Summary.Enemy.BarkSound;
                    enemySounds.AttackSound = (SoundClips)dfMobile.Summary.Enemy.AttackSound;
                }
            }

            return(go);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates enemy GameObjects based on spawn count specified in Foe resource (minimum of 1).
        /// Only use this when live enemy is to be first added to scene. Do not use when linking to site or deserializing.
        /// GameObjects created will be disabled, at origin, parentless, and have a new UID for LoadID.
        /// Caller must otherwise complete GameObject setup to suit their needs.
        /// </summary>
        /// <param name="reaction">Foe is hostile by default but can optionally set to passive.</param>
        /// <returns>GameObject[] array of 1-N foes. Array can be null or empty if create fails.</returns>
        public GameObject[] CreateFoeGameObjects(Vector3 position, int spawnOverride = -1, MobileReactions reaction = MobileReactions.Hostile)
        {
            List <GameObject> gameObjects = new List <GameObject>();

            // Get spawn count allowing for caller to override
            int totalSpawns = (spawnOverride >= 1) ? spawnOverride : spawnCount;

            // Generate GameObjects
            for (int i = 0; i < totalSpawns; i++)
            {
                // Generate enemy
                string         name       = string.Format("DaggerfallEnemy [{0}]", foeType.ToString());
                GameObject     go         = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, null, position);
                SetupDemoEnemy setupEnemy = go.GetComponent <SetupDemoEnemy>();
                if (setupEnemy != null)
                {
                    // Assign gender randomly
                    MobileGender gender;
                    if (UnityEngine.Random.Range(0f, 1f) < 0.5f)
                    {
                        gender = MobileGender.Male;
                    }
                    else
                    {
                        gender = MobileGender.Female;
                    }

                    // Configure enemy
                    setupEnemy.ApplyEnemySettings(foeType, reaction, gender);

                    // Align non-flying units with ground
                    DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild();
                    if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying)
                    {
                        GameObjectHelper.AlignControllerToGround(go.GetComponent <CharacterController>());
                    }

                    // Add QuestResourceBehaviour to GameObject
                    QuestResourceBehaviour questResourceBehaviour = go.AddComponent <QuestResourceBehaviour>();
                    questResourceBehaviour.AssignResource(this);
                }

                // Assign load id
                DaggerfallEnemy enemy = go.GetComponent <DaggerfallEnemy>();
                if (enemy)
                {
                    enemy.LoadID     = DaggerfallUnity.NextUID;
                    enemy.QuestSpawn = true;
                }

                // Disable GameObject, caller must set active when ready
                go.SetActive(false);

                // Add to list
                gameObjects.Add(go);
            }

            return(gameObjects.ToArray());
        }
Exemplo n.º 15
0
 /// <summary>
 /// Change enemy settings and configure in a single call.
 /// </summary>
 /// <param name="enemyType">Enemy type.</param>
 public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction)
 {
     EnemyType = enemyType;
     EnemyReaction = enemyReaction;
     ApplyEnemySettings();
 }
Exemplo n.º 16
0
 /// <summary>
 /// Change enemy settings and configure in a single call.
 /// </summary>
 /// <param name="enemyType">Enemy type.</param>
 public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction)
 {
     EnemyType     = enemyType;
     EnemyReaction = enemyReaction;
     ApplyEnemySettings();
 }
        /// <summary>
        /// Sets new enemy type.
        /// </summary>
        /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param>
        /// <param name="enemyType">Enemy type.</param>
        public void SetEnemy(DaggerfallUnity dfUnity, MobileEnemy enemy, MobileReactions reaction)
        {
            // Initial enemy settings
            summary.Enemy = enemy;
            summary.EnemyState = MobileStates.Move;
            summary.Enemy.Reactions = reaction;

            // Load enemy content
            int archive = GetTextureArchive();
            CacheRecordSizesAndFrames(dfUnity, archive);
            AssignMeshAndMaterial(dfUnity, archive);

            // Apply enemy state and update orientation
            lastOrientation = -1;
            ApplyEnemyState();

            // Raise setup flag
            summary.IsSetup = true;
        }
Exemplo n.º 18
0
 public void setMobileReaction(MobileReactions _reaction)
 {
     reaction = _reaction;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Create an enemy in the world and perform common setup tasks.
        /// </summary>
        public static GameObject CreateEnemy(string name, MobileTypes mobileType, Vector3 localPosition, Transform parent = null, MobileReactions mobileReaction = MobileReactions.Hostile)
        {
            // Create target GameObject
            string         displayName = string.Format("{0} [{1}]", name, mobileType.ToString());
            GameObject     go          = InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, displayName, parent, Vector3.zero);
            SetupDemoEnemy setupEnemy  = go.GetComponent <SetupDemoEnemy>();

            // Set position
            go.transform.localPosition = localPosition;

            // Assign humanoid gender randomly
            // This does not affect monsters like rats, bats, etc
            MobileGender gender;

            if (UnityEngine.Random.Range(0f, 1f) < 0.5f)
            {
                gender = MobileGender.Male;
            }
            else
            {
                gender = MobileGender.Female;
            }

            // Configure enemy
            setupEnemy.ApplyEnemySettings(mobileType, mobileReaction, gender);

            // Align non-flying units with ground
            DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild();

            if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying)
            {
                AlignControllerToGround(go.GetComponent <CharacterController>());
            }

            return(go);
        }