Esempio n. 1
0
        /// <summary>
        /// Process all potential reanimate dead within the radius.
        /// </summary>
        /// <returns>IEnumerator whilst delaying.</returns>
        public IEnumerator Start()
        {
            if (InitialDelay > 0)
            {                                                   // initial delay enabled
                yield return(new WaitForSeconds(InitialDelay)); // wait
            }
            yield return(new WaitForSeconds(InitialDelay));     // wait

            int        iReAnimatedSoFar = 0;
            bool       AllDone          = false;
            GameObject goMinion;

            while (!AllDone)
            {                                                                                                                                                             // scan loop for when all bones are tagged rather than just the parent
                AllDone = true;                                                                                                                                           // enable drop out
                if (MaxToReAnimate == 0 || iReAnimatedSoFar < MaxToReAnimate)
                {                                                                                                                                                         // limit how many get reanimated?
                    List <Transform> ltTargetsInRange = GlobalFuncs.FindAllTargetsWithinRange(transform.localPosition, Range, Layers, Tags, LineOfSightCheck, 0f, false); // search for deaders
                    if (ltTargetsInRange.Count > 0)
                    {                                                                                                                                                     // deaders found?
                        foreach (Transform tPotentialDeader in ltTargetsInRange)
                        {                                                                                                                                                 // process all transforms found
                            MagicAI mai = tPotentialDeader.GetComponentInParent <MagicAI>();                                                                              // attempt grab magic ai component
                            if (mai)
                            {                                                                                                                                             // found magic ai?
                                if (mai.MinionPrefab)
                                {                                                                                                                                         // valid is raise?
                                    if (GlobalFuncs.MAGICAL_POOL)
                                    {
                                        goMinion = GlobalFuncs.SpawnBasic(mai.MinionPrefab, 1, mai.transform, new RandomSphereOptions()
                                        {
                                        }, SpawnTarget.Any)[0];
                                    }
                                    else
                                    {
                                        goMinion = Instantiate(mai.MinionPrefab, mai.transform); // attempt spawn from transform
                                        goMinion.transform.SetParent(null);                      // unparent
                                    }
                                    var Agent = goMinion.GetComponent <NavMeshAgent>();
                                    if (Agent)
                                    {
                                        Agent.enabled = true;
                                    }
#if !VANILLA
                                    var vAI = goMinion.GetComponent <v_AICompanion>();
                                    if (vAI)
                                    {
                                        vAI.companion = GlobalFuncs.FindPlayerInstance().transform;
                                        vAI.Init();
                                        vAI.companionState = v_AICompanion.CompanionState.Follow;
                                        vAI.enabled        = true;
                                    }
#endif
                                    DestroyImmediate(mai.transform.gameObject); // kill original lying on the floor
                                    iReAnimatedSoFar += 1;                      // we have raised another, mwahahaha
                                    AllDone           = false;
                                    break;                                      // force rescan area
                                }
                            }
                        }
                    }
                }
            }
            if (DestroyDelay > 0)
            {                                                   // destruction enabled
                yield return(new WaitForSeconds(DestroyDelay)); // wait

                Destroy(gameObject);                            // destruct
            }
        }