/// <summary>
 /// Spawn all then destroy self (or return to the pool).
 /// </summary>
 void OnEnable()
 {
     if (Target != SpawnTarget.Any)
     {
         CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(PrefabsToSpawn, Delay, NoneSequential, transform, gameObject, iPoolSlotID, ForceFaceTrigger, Target));     // call shared spawner loop
     }
 }
Beispiel #2
0
        /// <summary>
        /// Collectable trigger via collider.
        /// </summary>
        /// <param name="col">Collider that has triggered the potential picup</param>
        void OnCollisionEnter(Collision col)
        {
            if ((TriggerLayers.value & 1 << col.gameObject.layer) == 1 << col.gameObject.layer)    // matching layer
            {
                CharacterBase levellingSystem = col.gameObject.GetComponent <CharacterBase>();
                if (levellingSystem)
                {
                    levellingSystem.Collectables[(int)Type].Value += Amount;
                    levellingSystem.ForceUpdateHUD();

                    // play audio
                    if (SourceOfAudio && PlayOnCollection)
                    {
                        SourceOfAudio.clip = PlayOnCollection;
                        SourceOfAudio.Play();
                    }

                    if (PrefabsToSpawn.Count > 0)
                    {
                        CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(PrefabsToSpawn, Delay, NoneSequential, transform, gameObject, iPoolSlotID, ForceFaceTrigger, Target));     // call shared spawner loop
                    }
                    else
                    {
                        // remove collectable from the game
                        GlobalFuncs.ReturnToThePoolOrDestroy(iPoolSlotID, gameObject);
                    }
                }
            }
        }
 /// <summary>
 /// Occurs when the attached collider is entered within by another collider, layers are in play to filter the potential collision sources.
 /// </summary>
 /// <param name="col">The collider that triggered the trap</param>
 void OnCollisionEnter(Collision col)
 {
     if (ColliderEnter)                                                                      // collider trap?
     {
         if ((TriggerLayers.value & 1 << col.gameObject.layer) == 1 << col.gameObject.layer) // matching layer
         {
             if (!ResetTrap)                                                                 // not a one off trap
             {
                 ColliderEnter = false;                                                      // disable trap reactivation
             }
             else  // reset trap enabled
             {
                 if (MaxResetTrap <= 1)     // has the number of times reset hasn't passed the max allowed?
                 {
                     ColliderEnter = false; // disable trap reactivation
                 }
                 else  // nope
                 {
                     MaxResetTrap -= 1;  // reduce the reset count
                 }
             }
             StartCoroutine(GlobalFuncs.SpawnAllDelayed(Traps, Delay, NoneSequential, transform, null, 0, ForceFaceTrigger, Target));  // trigger all traps the array
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Occurs when the projectile collides with another collider.
 /// </summary>
 /// <param name="c">Collider that caused the collision event.</param>
 void OnCollisionEnter(Collision c)
 {
     if (((HeatSeekLayers.value | GlobalFuncs.targetingLayerMaskCollision.value) & 1 << c.gameObject.layer) == 1 << c.gameObject.layer)
     {  // valid collide target
         bool bFound = false;
         if (ChainEffectCount > 0)
         {  // chain spell to another target?
             List <Transform> listTargetsInRange = GlobalFuncs.FindAllTargetsWithinRange(transform.position, HeatSeekRange, HeatSeekLayers, HeatSeekTags, true, 1.5f, true);
             if (listTargetsInRange.Count > 0)
             {                                                       // found more in range
                 sChainedToAlready += "-" + c.gameObject.name + "-"; // unique character names required, append name of current collision
                 foreach (Transform t in listTargetsInRange)
                 {
                     if (!sChainedToAlready.Contains("-" + t.gameObject.name + "-"))
                     {                                                                                                                                         // found new target
                         DestroyGameObjectAndSpawn md = GetComponent <DestroyGameObjectAndSpawn>();                                                            //  attempt gray destroy n spawn
                         if (md)
                         {                                                                                                                                     // found
                             md.enabled = false;                                                                                                               // disable it
                         }
                         MagicPool_Return mr = GetComponent <MagicPool_Return>();                                                                              // attempt get the pool return component
                         if (mr)
                         {                                                                                                                                     // found
                             mr.enabled = false;                                                                                                               // disable
                             mr.enabled = true;                                                                                                                // re enable, resetting the count down
                         }
                         tSpellTarget  = t;                                                                                                                    // re target the projectile
                         v3SpellTarget = tSpellTarget.position;                                                                                                // update position of the transform
                         FollowTarget  = true;                                                                                                                 // ensure moving target is followed
                         bFound        = true;                                                                                                                 // flag don't destroy
                         if (ParticlesOnCollision.Count > 0)
                         {                                                                                                                                     // has spawns?
                             StartCoroutine(GlobalFuncs.SpawnAllDelayed(ParticlesOnCollision, SpawnDelay, NoneSequential, transform, null, 0, false, Target)); // spawn all but dont kill the projectile
                         }
                         ChainEffectCount -= 1;                                                                                                                // lower the chain count
                         break;                                                                                                                                // work complete
                     }
                 }
             }
         }
         if (!bFound)
         {                                                                                                                                                             // run out of chain-able enemies or chaining not enabled
             if (ParticlesOnCollision.Count > 0)
             {                                                                                                                                                         // has spawns?
                 if (gameObject.activeInHierarchy)
                 {                                                                                                                                                     // failsafe, not already returned to the pool
                     StartCoroutine(GlobalFuncs.SpawnAllDelayed(ParticlesOnCollision, SpawnDelay, NoneSequential, transform, gameObject, iPoolSlotID, false, Target)); // spawn all then kill the projectile
                 }
             }
             else
             {
                 GlobalFuncs.ReturnToThePoolOrDestroy(iPoolSlotID, gameObject);  // kill or return projectile to the pool
             }
         }
     }
 }
Beispiel #5
0
 /// <summary>
 /// I have died, give XP to player and spawn any death spawns.
 /// </summary>
 public virtual void OnDead()
 {
     if (GlobalFuncs.DEBUGGING_MESSAGES)
     {
         Debug.Log(transform.name + " change state to Dead");
     }
     GlobalFuncs.GiveXPToPlayer(XPToGive);                                                                                                                                                                                  // update player XP
     bMagicAttacking = false;                                                                                                                                                                                               // ensure no more spells launched
     bPatrolling     = false;                                                                                                                                                                                               // ensure patrol actions stopped
     StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnDeath, 0f, NoneSequentialSpawns, transform, null, 0, false, (gameObject.tag == "Enemy" ? SpawnTarget.Friend : SpawnTarget.Enemy)));                                  // trigger all death spawns the the array
     StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnBodyRemoval, GlobalFuncs.EnemyDestroyDelay, NoneSequentialSpawns, transform, null, 0, false, (gameObject.tag == "Enemy" ? SpawnTarget.Friend : SpawnTarget.Enemy))); // trigger all death spawns the the array
     Destroy(gameObject, GlobalFuncs.EnemyDestroyDelay);                                                                                                                                                                    // remove self when dead after global time limit
 }
 /// <summary>
 /// Less efficient than collision mode, check at the specified frequency whether the
 /// </summary>
 void Update()
 {
     if (ProximityEnter)                                                                                                                  // proximity trap enabled?
     {
         if (Time.time > (TimeSinceLastCheck + CheckRate))                                                                                // time for a distance check?
         {
             TimeSinceLastCheck = Time.time;                                                                                              // update the last checked time
             if (Vector3.Distance(transform.position, goPlayer.transform.position) < Proximity)                                           // within range
             {
                 StartCoroutine(GlobalFuncs.SpawnAllDelayed(Traps, Delay, NoneSequential, transform, null, 0, ForceFaceTrigger, Target)); // trigger all traps in the array
                 ProximityEnter = false;                                                                                                  // disable the trap
             }
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Initialise listeners and component references.
        /// </summary>
        protected virtual void Start()
        {
            // initialise invector AI handling
            player    = GlobalFuncs.FindPlayerInstance();
            agent     = GetComponent <NavMeshAgent>();
            animator  = GetComponent <Animator>();
            inventory = GetComponent <MagicAIItemManager>();
#if !VANILLA
            ai = GetComponent <v_AIController>();
            if (ai)
            {                                                          // don't start if invector AI and all components are not present
                // invector ai event handlers
                ai.onReceiveDamage.AddListener(OnReceiveDamage_Chase); // listen for damage to enable chase when out of FOV
                ai.onChase.AddListener(delegate { OnChase(); });       // listen for start of chase mode
                ai.onIdle.AddListener(delegate { OnIdle(); });         // listen for start of idle mode
                //ai.onPatrol.AddListener(delegate { OnPatrol(); });  // listen for start of idle mode
                ai.onDead.AddListener(delegate { OnDead(); });         // listen for sudden death

                // store original FOV
                fOriginal_maxDetectDistance    = ai.maxDetectDistance;
                fOriginal_distanceToLostTarget = ai.distanceToLostTarget;
                fOriginal_fieldOfView          = ai.fieldOfView;
            }
#else
            // handle non invector events
#endif

            // add a listener to the leveling component if available
            CharacterBase levelingSystem = GetComponentInParent <CharacterBase>();
            if (levelingSystem)
            {
                useMana = new SetIntValue(levelingSystem.UseMana);
                levelingSystem.NotifyUpdateHUD += new CharacterBase.UpdateHUDHandler(UpdateHUDListener);
                levelingSystem.ForceUpdateHUD();
            }

#if !VANILLA
            // make short list of spells in inventory
            if (inventory && AnimatorTrigger.Length > 0 && HasMagicAbilities)
            {
                SpellsShortList = new List <MagicAIAvailableSpell>();                        // init the list
                foreach (ItemReference ir in inventory.startItems)
                {                                                                            // process all start items
                    vItem item = inventory.itemListData.items.Find(t => t.id.Equals(ir.id)); // find the vItem by id
                    if (item.type == vItemType.Spell)
                    {                                                                        // only after spells
                        SpellsShortList.Add(new MagicAIAvailableSpell()
                        {
                            MagicID  = item.attributes.Find(ia => ia.name.ToString() == "MagicID").value,
                            ManaCost = item.attributes.Find(ia => ia.name.ToString() == "ManaCost").value
                        });  // add to the short list
                    }
                }
                if (SpellsShortList.Count == 0)
                {                           // none found
                    SpellsShortList = null; // reset back to null for fast checking
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Warning spells NOT found in magic AI inventory");
                    }
                }
            }
#endif

            // birth animation & magic spawning
            if (BirthStartTrigger != "")
            {                                                                                                                                                                                                                   // birth animation specified
                animator.SetTrigger(BirthStartTrigger);                                                                                                                                                                         // trigger the random magic state selector
            }
            CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnBirth, BirthSpawnDelay, NoneSequentialSpawns, transform, null, 0, false, (gameObject.tag == "Enemy" ? SpawnTarget.Friend : SpawnTarget.Enemy))); // trigger all birth spawns the the array
        }
Beispiel #8
0
 /// <summary>
 /// Simple run the spawn loop with delays (from other spawner's).
 /// </summary>
 void Start()
 {
     CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnMe, Delay, NoneSequential, transform, gameObject, iPoolSlotID, ForceFaceTrigger, Target));  // trigger all traps the the array
 }
Beispiel #9
0
        /// <summary>
        /// Save the game and load the next scene when collider trigger entered by the player.
        /// </summary>
        /// <param name="other">Collider that has entered the trigger.</param>
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag.Equals("Player"))
            {     // only player can trigger
                if (SceneToLoad != "")
                { // fail safe
                    // spawn all
                    if (SpawnOnEnter.Count > 0)
                    {
                        StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnEnter, SpawnDelay, NoneSequentialSpawns, transform, null, 0, false, SpawnTarget.Any));  // trigger all spawns the the array
                    }

                    // save to data layer
                    LevelingSystem = other.gameObject.GetComponent <CharacterBase>();
                    if (!LevelingSystem)
                    {  // not found?
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("Leveling system not found on player");
                        }
                    }
                    else
                    {  // all good
                       // save the game
                        LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, SceneToLoad, -1);
                        MainMenu MainMenuSystem = GlobalFuncs.TheMainMenu();
                        if (MainMenuSystem)
                        {
                            MainMenuSystem.LatestSaveGameID = LevelingSystem.LastSaveGameID;

                            // confirm save to user
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true);
                            MainMenuSystem.SaveGameMessage.text = "Save Complete..";
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(0f, 3f, true);

                            // load the next scene
                            MainMenu_FadingLoad Fader = MainMenuSystem.gameObject.GetComponent <MainMenu_FadingLoad>();
                            if (Fader)
                            {
                                Fader.BeginFade(1);
                                Fader.LoadSceneAsync(SceneToLoad, LoadDelay);  // start the load with progress bar
                            }
                            else
                            {
                                if (GlobalFuncs.DEBUGGING_MESSAGES)
                                {
                                    Debug.Log("Main menu system NOT found in scene");
                                }
                            }
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Main menu system NOT found in scene");
                            }
                        }
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Scene to load is NOT set");
                    }
                }
            }
        }
Beispiel #10
0
 /// <summary>
 /// Trigger the entire spawn trap array directly via delgate or script
 /// </summary>
 public void ManualTriggerTrap()
 {
     StartCoroutine(GlobalFuncs.SpawnAllDelayed(Traps, Delay, NoneSequential, transform, null, 0, ForceFaceTrigger, Target));  // trigger all traps the array
 }