Beispiel #1
0
        public void SetupScriptableObjects()
        {
            if (SystemGameManager.MyInstance == null)
            {
                Debug.LogError(gameObject.name + ": System Game Manager Not Found In The Scene.");
                return;
            }
            if (prerequisiteConditions != null)
            {
                foreach (PrerequisiteConditions tmpPrerequisiteConditions in prerequisiteConditions)
                {
                    if (tmpPrerequisiteConditions != null)
                    {
                        //Debug.Log(gameObject.name + ".SetupScriptableObjects(): setting up prerequisites");
                        tmpPrerequisiteConditions.SetupScriptableObjects(this);

                        // add this so unit spawn nodes can have their prerequisites properly set on the first check
                        tmpPrerequisiteConditions.UpdatePrerequisites(false);
                    }
                }
            }

            unitProfiles = new List <UnitProfile>();
            if (unitProfileNames != null)
            {
                foreach (string unitProfileName in unitProfileNames)
                {
                    if (unitProfileName != null && unitProfileName != string.Empty)
                    {
                        UnitProfile unitProfile = SystemUnitProfileManager.MyInstance.GetResource(unitProfileName);
                        if (unitProfile != null)
                        {
                            unitProfiles.Add(unitProfile);
                        }
                        else
                        {
                            Debug.LogError(gameObject.name + ": Unit Profile: " + unitProfileName + " not found while initializing Unit Unit Spawn Node.  Check Inspector!");
                        }
                    }
                }
            }

            if (unitToughness == null && defaultToughness != null && defaultToughness != string.Empty)
            {
                UnitToughness tmpToughness = SystemUnitToughnessManager.MyInstance.GetResource(defaultToughness);
                if (tmpToughness != null)
                {
                    unitToughness = tmpToughness;
                }
                else
                {
                    Debug.LogError("Unit Toughness: " + defaultToughness + " not found while initializing Unit Profiles.  Check Inspector!");
                }
            }
        }
Beispiel #2
0
        public void CommonSpawn(int unitLevel, int extraLevels, bool dynamicLevel, GameObject spawnPrefab, UnitToughness toughness = null)
        {
            //Debug.Log(gameObject.name + ".UnitSpawnNode.CommonSpawn()");
            if (spawnPrefab == null || PlayerManager.MyInstance.MyCharacter == null)
            {
                return;
            }
            //GameObject spawnReference = Instantiate(spawnPrefabs[spawnIndex], GetSpawnLocation(),  Quaternion.identity);
            // testing, re-enable transform position so mobs don't spawn way above the map if their prefab has a location set
            GameObject spawnReference = Instantiate(spawnPrefab, gameObject.transform.position, gameObject.transform.rotation);

            spawnReference.name = spawnReference.name + SystemGameManager.MyInstance.GetSpawnCount();
            //Debug.Log(gameObject.name + ".UnitSpawnNode.Spawn(): gameObject spawned at: " + spawnReference.transform.position);
            Vector3          newSpawnLocation = Vector3.zero;
            Vector3          newSpawnForward  = Vector3.forward;
            PersistentObject persistentObject = spawnReference.GetComponent <PersistentObject>();

            if (persistentObject != null)
            {
                PersistentState persistentState = persistentObject.GetPersistentState();
                if (persistentState != null)
                {
                    newSpawnLocation = persistentState.Position;
                    newSpawnForward  = persistentState.Forward;
                }
                else
                {
                    newSpawnLocation = GetSpawnLocation();
                    newSpawnForward  = transform.forward;
                }
            }
            else
            {
                newSpawnLocation = GetSpawnLocation();
                newSpawnForward  = transform.forward;
            }
            //Debug.Log("UnitSpawnNode.Spawn(): newSpawnLocation: " + newSpawnLocation);
            NavMeshAgent navMeshAgent = spawnReference.GetComponent <NavMeshAgent>();
            AIController aIController = spawnReference.GetComponent <AIController>();

            aIController.MyStartPosition = newSpawnLocation;
            //Debug.Log("UnitSpawnNode.Spawn(): navhaspath: " + navMeshAgent.hasPath + "; isOnNavMesh: " + navMeshAgent.isOnNavMesh + "; isOnOffMeshLink: " + navMeshAgent.isOnOffMeshLink + "; pathpending: " + navMeshAgent.pathPending + "; warping now!");
            //spawnReference.transform.position = newSpawnLocation;
            navMeshAgent.Warp(newSpawnLocation);
            spawnReference.transform.forward = newSpawnForward;
            //Debug.Log("UnitSpawnNode.Spawn(): afterMove: navhaspath: " + navMeshAgent.hasPath + "; isOnNavMesh: " + navMeshAgent.isOnNavMesh + "; pathpending: " + navMeshAgent.pathPending);
            CharacterUnit _characterUnit = spawnReference.GetComponent <CharacterUnit>();

            if (respawnOn == respawnCondition.Despawn)
            {
                if (_characterUnit != null)
                {
                    _characterUnit.OnDespawn += HandleDespawn;
                }
            }
            else if (respawnOn == respawnCondition.Loot)
            {
                LootableCharacter _lootableCharacter = spawnReference.GetComponent <LootableCharacter>();
                if (_lootableCharacter != null)
                {
                    _lootableCharacter.OnLootComplete += HandleLootComplete;
                }
            }
            else if (respawnOn == respawnCondition.Death)
            {
                if (_characterUnit != null && _characterUnit.MyCharacter != null && _characterUnit.MyCharacter.CharacterStats != null)
                {
                    _characterUnit.MyCharacter.CharacterStats.OnDie += HandleDie;
                }
            }
            // don't override an existing toughness
            if (_characterUnit.MyCharacter.UnitToughness == null)
            {
                //Debug.Log("UnitSpawnNode.Spawn(): setting toughness to null on gameObject: " + spawnReference.name);
                _characterUnit.MyCharacter.SetUnitToughness(toughness);
            }
            int _unitLevel = (dynamicLevel ? PlayerManager.MyInstance.MyCharacter.CharacterStats.Level : unitLevel) + extraLevels;

            _characterUnit.MyCharacter.CharacterStats.SetLevel(_unitLevel);
            _characterUnit.MyCharacter.CharacterStats.TrySpawnDead();
            spawnReferences.Add(spawnReference);
        }
Beispiel #3
0
 public void ManualSpawn(int unitLevel, int extraLevels, bool dynamicLevel, GameObject spawnPrefab, UnitToughness toughness)
 {
     CommonSpawn(unitLevel, extraLevels, dynamicLevel, spawnPrefab, toughness);
 }
        public void CommonSpawn(int unitLevel, int extraLevels, bool dynamicLevel, GameObject spawnPrefab, UnitToughness toughness = null)
        {
            //Debug.Log(gameObject.name + "UnitSpawnNode.CommonSpawn()");
            if (spawnPrefab == null || PlayerManager.MyInstance.MyCharacter == null)
            {
                return;
            }
            //GameObject spawnReference = Instantiate(spawnPrefabs[spawnIndex], GetSpawnLocation(),  Quaternion.identity);
            GameObject spawnReference = Instantiate(spawnPrefab);

            spawnReference.name = spawnReference.name + SystemGameManager.MyInstance.GetSpawnCount();
            //Debug.Log("UnitSpawnNode.Spawn(): gameObject spawned at: " + spawnReference.transform.position);
            Vector3 newSpawnLocation = GetSpawnLocation();
            //Debug.Log("UnitSpawnNode.Spawn(): newSpawnLocation: " + newSpawnLocation);
            NavMeshAgent navMeshAgent = spawnReference.GetComponent <NavMeshAgent>();
            AIController aIController = spawnReference.GetComponent <AIController>();

            aIController.MyStartPosition = newSpawnLocation;
            //Debug.Log("UnitSpawnNode.Spawn(): navhaspath: " + navMeshAgent.hasPath + "; isOnNavMesh: " + navMeshAgent.isOnNavMesh + "; isOnOffMeshLink: " + navMeshAgent.isOnOffMeshLink + "; pathpending: " + navMeshAgent.pathPending + "; warping now!");
            //spawnReference.transform.position = newSpawnLocation;
            navMeshAgent.Warp(newSpawnLocation);
            spawnReference.transform.forward = transform.forward;
            //Debug.Log("UnitSpawnNode.Spawn(): afterMove: navhaspath: " + navMeshAgent.hasPath + "; isOnNavMesh: " + navMeshAgent.isOnNavMesh + "; pathpending: " + navMeshAgent.pathPending);
            CharacterUnit _characterUnit = spawnReference.GetComponent <CharacterUnit>();

            if (_characterUnit != null)
            {
                _characterUnit.OnDespawn += HandleDespawn;
            }
            // don't override an existing toughness
            if (_characterUnit.MyCharacter.UnitToughness == null)
            {
                //Debug.Log("UnitSpawnNode.Spawn(): setting toughness to null on gameObject: " + spawnReference.name);
                _characterUnit.MyCharacter.SetUnitToughness(toughness);
            }
            int _unitLevel = (dynamicLevel ? PlayerManager.MyInstance.MyCharacter.CharacterStats.Level : unitLevel) + extraLevels;

            _characterUnit.MyCharacter.CharacterStats.SetLevel(_unitLevel);
            _characterUnit.MyCharacter.CharacterStats.TrySpawnDead();
            spawnReferences.Add(spawnReference);
        }
        public void CommonSpawn(int unitLevel, int extraLevels, bool dynamicLevel, UnitProfile unitProfile, UnitToughness toughness = null)
        {
            //Debug.Log(gameObject.name + ".UnitSpawnNode.CommonSpawn()");

            // prevent a coroutine that finished during a level load from spawning a character
            if (disabled == true)
            {
                return;
            }
            if (unitProfile == null || playerManager.MyCharacter == null)
            {
                return;
            }

            int            _unitLevel     = (dynamicLevel ? playerManager.MyCharacter.CharacterStats.Level : unitLevel) + extraLevels;
            UnitController unitController = unitProfile.SpawnUnitPrefab(null, transform.position, transform.forward, UnitControllerMode.AI, _unitLevel);

            if (unitController == null)
            {
                // something went wrong.  None of the code below will work, so might as well return
                return;
            }

            Vector3 newSpawnLocation = Vector3.zero;
            Vector3 newSpawnForward  = Vector3.forward;

            // lookup persistent position, or use navmesh agent to get a valid position (in case this spawner was not placed on walkable terrain)
            if (unitController.PersistentObjectComponent.PersistObjectPosition == true)
            {
                //Debug.Log(gameObject.name + ".UnitSpawnNode.CommonSpawn(): persist ojbect position is true");
                PersistentState persistentState = unitController.PersistentObjectComponent.GetPersistentState();
                if (persistentState != null)
                {
                    // since we will be using navMeshAgent.warp, do not attempt to move unit manually
                    unitController.PersistentObjectComponent.MoveOnStart = false;
                    newSpawnLocation = persistentState.Position;
                    newSpawnForward  = persistentState.Forward;
                }
                else
                {
                    newSpawnLocation = GetSpawnLocation();
                    newSpawnForward  = transform.forward;
                }
            }
            else
            {
                newSpawnLocation = GetSpawnLocation();
                newSpawnForward  = transform.forward;
            }

            // now that we have a good final position and rotation, set it
            unitController.StartPosition = newSpawnLocation;
            unitController.NavMeshAgent.Warp(newSpawnLocation);
            unitController.transform.forward = newSpawnForward;


            //Debug.Log("UnitSpawnNode.Spawn(): afterMove: navhaspath: " + navMeshAgent.hasPath + "; isOnNavMesh: " + navMeshAgent.isOnNavMesh + "; pathpending: " + navMeshAgent.pathPending);
            CharacterUnit _characterUnit   = null;
            CharacterUnit tmpCharacterUnit = unitController.CharacterUnit;

            if (tmpCharacterUnit == null)
            {
                Debug.LogError("Interactable had no characterUnit");
                return;
            }
            _characterUnit = tmpCharacterUnit;

            if (respawnOn == respawnCondition.Despawn)
            {
                _characterUnit.OnDespawn += HandleDespawn;
            }
            else if (respawnOn == respawnCondition.Loot)
            {
                LootableCharacterComponent tmpLootableCharacter = LootableCharacterComponent.GetLootableCharacterComponent(unitController);
                if (tmpLootableCharacter != null)
                {
                    // there can only be one of these types of object on an interactable
                    // interesting note : there is no unsubscribe to this event.  Unit spawn nodes exist for the entire scene and are only destroyed at the same time as the interactables
                    // should we make an unsubscribe anyway even though it would never be called?
                    tmpLootableCharacter.OnLootComplete += HandleLootComplete;
                }
            }
            else if (respawnOn == respawnCondition.Death)
            {
                if (_characterUnit.BaseCharacter != null && _characterUnit.BaseCharacter.CharacterStats != null)
                {
                    _characterUnit.BaseCharacter.CharacterStats.OnDie += HandleDie;
                }
            }
            // don't override an existing toughness
            if (_characterUnit.BaseCharacter.UnitToughness == null && toughness != null)
            {
                //Debug.Log("UnitSpawnNode.Spawn(): setting toughness to null on gameObject: " + spawnReference.name);
                _characterUnit.BaseCharacter.SetUnitToughness(toughness, true);
            }
            unitController.Init();
            spawnReferences.Add(unitController);
        }
 public void ManualSpawn(int unitLevel, int extraLevels, bool dynamicLevel, UnitProfile unitProfile, UnitToughness toughness)
 {
     CommonSpawn(unitLevel, extraLevels, dynamicLevel, unitProfile, toughness);
 }