示例#1
0
        public override Dictionary <PrefabProfile, GameObject> Cast(IAbilityCaster source, Interactable target, Interactable originalTarget, AbilityEffectContext abilityEffectInput)
        {
            //Debug.Log("StatusEffect.Cast(" + source.name + ", " + (target? target.name : "null") + ")");
            if (!CanUseOn(target, source))
            {
                return(null);
            }
            if (target == null)
            {
                // we can't mount anything if there is no target
                return(null);
            }
            Dictionary <PrefabProfile, GameObject> returnObjects = base.Cast(source, target, originalTarget, abilityEffectInput);

            UnitController mountUnitController = unitProfile.SpawnUnitPrefab(source.AbilityManager.UnitGameObject.transform.parent, source.AbilityManager.UnitGameObject.transform.position, source.AbilityManager.UnitGameObject.transform.forward, UnitControllerMode.Mount);

            if (mountUnitController != null)
            {
                source.AbilityManager.SetMountedState(mountUnitController, unitProfile);
            }
            return(returnObjects);
        }
示例#2
0
        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);
        }