예제 #1
0
 /// <summary>
 /// Actually find the player instance.
 /// </summary>
 public override void OnEnter()
 {
     if (player.Value == null)
     {
         player.Value = GlobalFuncs.FindPlayerInstance();
     }
 }
예제 #2
0
        /// <summary>
        /// Occurs on activation, sets up the projectile for targeting.
        /// </summary>
        void OnEnable()
        {
            sChainedToAlready = "";  // reset chain list

            if (!player)
            {
                player = GlobalFuncs.FindPlayerInstance();           // grab the player
            }
            if (player)
            {                                                   // found?
                if (Target == SpawnTarget.Enemy)
                {                                               // is the source the player
                    if (LockOnHasPriority)
                    {                                           // attempt to use the lock on target
                        tSpellTarget = GlobalFuncs.GetLockOn(); // take the target if any
                    }
                    if (!tSpellTarget && EnableHeatSeeking)
                    {  // no lock on and heat seeking mode enabled
                        tSpellTarget = GlobalFuncs.GetTargetWithinRange(transform.position, HeatSeekRange, HeatSeekLayers, HeatSeekTags, HeatSeekNearest, true, 1.5f, true);
                    }
                }
                else if (EnableHeatSeeking)
                {                                    // enemy spell
                    tSpellTarget = player.transform; // that homes on the player
                }

                // update the local target seek
                if (tSpellTarget)
                {                                             // target found?
                    v3SpellTarget    = tSpellTarget.position; // update the seek position
                    v3SpellTarget.y += HeightAdjust;          // update height (avoid hiting target feet)
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Occurs when enabled by the magical pool, sets up the teleport.
        /// </summary>
        public virtual void OnEnable()
        {
            if (TargetTags != null)
            {  // ensure creating pool master copy doesnt activate it
                // set gameobject to teleport
                if (transform.parent)
                {                                                                // if run via the vMagicAttackBehaviour class then set the KeepParent flag
                    goTeleportMe = transform.parent.transform.parent.gameObject; // take the individual to teleport to, enemy or player
                    goTeleportMe.transform.parent = null;                        // unparent
                }
                else
                {                                                    // no parent so assume player as fallback
                    goTeleportMe = GlobalFuncs.FindPlayerInstance(); // find the player gameobject
                }

                // init the teleport
                if (goTeleportMe)
                {                                               // failsafe, should always be true
                    if (goTeleportMe.tag == "Player")
                    {                                           // am i the player
                        tSpellTarget = GlobalFuncs.GetLockOn(); // do i have a lock
                    }
                    if (!tSpellTarget)
                    {  // no lock or enemy ai
                        tSpellTarget = GlobalFuncs.GetTargetWithinRange(goTeleportMe.transform.position, MaxDistance, TargetLayers, TargetTags, NearestTarget, false, 0f, true);
                    }

                    // lets go, unless no target
                    if (tSpellTarget)
                    {                                                    // valid?
                        CoTeleport = StartCoroutine(TeleportAtTarget()); // beam me up
                    }
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Find the player for proximity mode
 /// </summary>
 void Start()
 {
     if (ProximityEnter)                                        // proximity trap?
     {
         goPlayer           = GlobalFuncs.FindPlayerInstance(); // cache player
         TimeSinceLastCheck = Time.time;                        // cache the first check time
     }
 }
예제 #5
0
        /// <summary>
        /// Loads the selected save game scene from when selected in the GUI.
        /// </summary>
        /// <param name="SaveGameID">ID of the save game to load from the data layer.</param>
        public void LoadGame(int SaveGameID)
        {
            // clear player state
            GlobalFuncs.TheDatabase().ClearInventoryAndHUD();

            // find the leveling system
            if (!LevelingSystem)
            {
                GameObject player = GlobalFuncs.FindPlayerInstance();
                if (player)
                {
                    LevelingSystem = player.GetComponent <CharacterBase>();
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Unable to find player");
                    }
                }
            }
            if (!LevelingSystem)
            {  // not found?
                if (GlobalFuncs.DEBUGGING_MESSAGES)
                {
                    Debug.Log("Levelling system not found on player");
                }
            }
            else
            {  // all good
                // load character from the data layer
                LevelingSystem.SaveSlotID     = SelectedSlotID;
                LevelingSystem.LastSaveGameID = SaveGameID;
                string SceneName = GlobalFuncs.TheDatabase().LoadPlayerState(ref LevelingSystem, SaveGameID);

                // close the menu and load the scene
                if (SceneName != "")
                {
#if !VANILLA
                    Inventory.gameObject.SetActive(true);
#endif
                    LoadGameWindow.SetActive(false);
                    FirstWindow.gameObject.SetActive(false);
                    Fader.BeginFade(1);
                    isOpen    = false;
                    lockInput = false;
                    Fader.LoadSceneAsync(SceneName);  // start the load with progress bar
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Failed to load save game ID " + SaveGameID);
                    }
                }
            }
        }
        /// <summary>
        /// Randomly moves to another animator state upon state enter.
        /// </summary>
        /// <param name="animator">Reference to the parent animator.</param>
        /// <param name="stateInfo">Information about the state.</param>
        /// <param name="layerIndex">Index of the animator layer.</param>
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            GameObject player = GlobalFuncs.FindPlayerInstance();  // grab the player

            if (player)
            {
                // work out the distance to the player
                float dist = Vector3.Distance(animator.transform.position, player.transform.position);

                // find available attacks
                int[] iAvailableAttacks = null;
                for (int i = 0; i < Attacks.Count; i++)
                {
                    // add to the available list if has no range or is in range
                    if (!Attacks[i].CheckRange || (dist >= Attacks[i].MinAttackRange && dist <= Attacks[i].MaxAttackRange))
                    {
                        for (int w = 0; w < Attacks[i].Weight + 1; w++)
                        {
                            if (iAvailableAttacks == null)
                            {
                                iAvailableAttacks = new int[1];  // create element 0
                            }
                            else
                            {                                                                            // not empty
                                Array.Resize <int>(ref iAvailableAttacks, iAvailableAttacks.Length + 1); // extend array by 1
                            }
                            iAvailableAttacks[iAvailableAttacks.Length - 1] = i;                         // add to the slot bag
                        }
                    }
                }

                // now lets attack
                if (iAvailableAttacks != null)
                { // cause the attack, which should be linked to this state matching conditions on the transition (named in RandomAttackName)
                    // random attack selection
                    int iRandomAttack = UnityEngine.Random.Range(1, iAvailableAttacks.Length + 1) - 1;

                    // face the player?
                    if (Attacks[iAvailableAttacks[iRandomAttack]].FacePlayer)
                    {
                        animator.transform.LookAt(player.transform.localPosition);
                    }

                    // attack
                    animator.SetInteger(RandomAttackName, Attacks[iAvailableAttacks[iRandomAttack]].MagicId);
                }
                else
                {  // all attacks fail range check, show default
                    animator.SetInteger(RandomAttackName, DefaultAttack);
                }
            }
            else
            {  // player not found, show default
                animator.SetInteger(RandomAttackName, DefaultAttack);
            }
        }
예제 #7
0
        /// <summary>
        /// Save the current scene/character state to the data layer
        /// </summary>
        public void SaveGame()
        {
            if (!LevelingSystem)
            {
                GameObject player = GlobalFuncs.FindPlayerInstance();
                if (player)
                {
                    LevelingSystem = player.GetComponent <CharacterBase>();
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Unable to find player");
                    }
                }
            }
            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, SceneManager.GetActiveScene().name, -1);
                LatestSaveGameID = LevelingSystem.LastSaveGameID;

                // hide the menu and enable time
                foreach (GameObject ui in UserInterface)
                {
                    ui.SetActive(true);
                }
#if !VANILLA
                Inventory.gameObject.SetActive(true);
#endif
                FirstWindow.gameObject.SetActive(false);
                isOpen         = false;
                lockInput      = false;
                Time.timeScale = 1f;

                // confirm save to user
                SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true);
                SaveGameMessage.text = "Save Complete..";
                SaveGameMessage.CrossFadeAlpha(0f, 3f, true);
            }
        }
예제 #8
0
        /// <summary>
        /// Occurs when a scene is loaded completely, assigns the player to the level spawn point and reactivates components.
        /// </summary>
        /// <param name="scene">Current scene that has finished loading.</param>
        /// <param name="mode">Scene load method (Additive or Singular).</param>
        public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
        {
            // flag whether the lobby was just loaded (causes main menu to open auto)
            GameMainMenu.isNotLobby = (GameMainMenu.LobbySceneName != scene.name);
            GameMainMenu.SaveGameButton.SetActive(GameMainMenu.isNotLobby);
            GameMainMenu.LoadGameButton.SetActive(GameMainMenu.isNotLobby);
            GameMainMenu.ContinueButton.SetActive(!GameMainMenu.isNotLobby);

            // find the spawn point and update the player position
            GameObject psp = GameObject.Find("SpawnPoint");

            if (psp)
            {
                GameObject player = GlobalFuncs.FindPlayerInstance();
                //GameController.spawnPoint = psp.transform;
                player.transform.position = psp.transform.position;
                player.transform.rotation = psp.transform.rotation;
            }
            else
            {
                if (GameMainMenu.LobbySceneName != scene.name)
                {
                    Debug.Log("Spawn Point NOT Found");
                }
            }

            // start time and fade in from full screen texture
#if !VANILLA
            PlayerCamera.Init();
#endif
            foreach (GameObject ui in GameMainMenu.UserInterface)
            {
                ui.SetActive(GameMainMenu.isNotLobby);
            }
            Time.timeScale = 1f;
            BeginFade(-1);
            Debug.Log("Load Level (" + scene.name + ") Complete");

            // scene change sound
            if (GameMainMenu.SourceOfAudio && GameMainMenu.PlayOnSpawn)
            {                                                                                                                                            // play audio?
                if (!GameMainMenu.SourceOfAudio.isPlaying)
                {                                                                                                                                        // ignore if already playing
                    GameMainMenu.SourceOfAudio.clip = (GameMainMenu.LobbySceneName != scene.name ? GameMainMenu.PlayOnSpawn : GameMainMenu.PlayOnDeath); // set the clip
                    GameMainMenu.SourceOfAudio.Play();                                                                                                   // play the clip
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Load the most recent save with a delay.
        /// </summary>
        /// <returns>IEnumerator until specified delay has passed.</returns>
        public IEnumerator delayedContinue()
        {
            ReAnimating = true;        // disable main menu
#if !VANILLA
            Inventory.enabled = false; // and the inventory keys
#endif

            // disable leveling system (otherwise health regen reanimates the character)
            LevelingSystem.enabled = false;
#if !VANILLA
            var invectorController = GlobalFuncs.FindPlayerInstance().GetComponent <vCharacter>();
            invectorController.enabled = false;
#endif

            // disable UI
            foreach (GameObject ui in UserInterface)
            {
                ui.SetActive(false);
            }

            // death sound
            if (SourceOfAudio && PlayOnDeath)
            {                                         // play audio?
                if (!SourceOfAudio.isPlaying)
                {                                     // ignore if already playing
                    SourceOfAudio.clip = PlayOnDeath; // set the clip
                    SourceOfAudio.Play();             // play the clip
                }
            }

            // wait
            yield return(new WaitForSeconds(DeathLoadDelay));

            // restart the game from the last save
            LevelingSystem.enabled = true;
#if !VANILLA
            invectorController.enabled = true;
            Inventory.enabled          = true;
#endif
            LevelingSystem.reCalcCore(true);
            ReAnimating = false;

            ContinueGame();
        }
예제 #10
0
        /// <summary>
        /// Disable the main menu and redraw the character display.
        /// </summary>
        void OnEnable()
        {
            // deactivate main menu
            if (ParentMenu)
            {
                ParentMenu.SetActive(false);
            }

            if (!ScreenDrawnAlready)
            {  // draw the full display on first open
#if !VANILLA
                control = GetComponentInParent <vInventory>();
#endif
                if (Header && AttributeIcon && AttributeName && AttributeValue)
                {
                    DefHeaderTXT = Header.gameObject.GetComponent <Text>();
                    DefAttribTXT = AttributeName.gameObject.GetComponent <Text>();
                    DefValueTXT  = AttributeValue.gameObject.GetComponent <Text>();
                    DefPlusTXT   = AttributeSpendPlus.gameObject.GetComponent <Text>();
                    if (DefHeaderTXT && DefAttribTXT && DefValueTXT && DefPlusTXT)
                    {
                        GameObject player = GlobalFuncs.FindPlayerInstance();
                        if (player)
                        {
                            levelingSystem = player.GetComponent <CharacterBase>();
                            if (levelingSystem)
                            {  // all required components found, draw the stats with labels
                                CurrentPane = -1;
                                reDrawAttributes();
                                ScreenDrawnAlready = true;
                            }
                            else
                            {
                                if (GlobalFuncs.DEBUGGING_MESSAGES)
                                {
                                    Debug.Log("Player Leveling System NOT found");
                                }
                            }
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Player NOT found");
                            }
                        }
                    }
                    else
                    {
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("GUI Text component is required on the default header/attribute name objects");
                        }
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Default UI rect transforms NOT set");
                    }
                }
            }
            else
            {  // already have the components
                reDrawAttributes();
            }
        }
예제 #11
0
 /// <summary>
 /// Initialise.
 /// </summary>
 void Start()
 {
     MyTransform     = transform;
     PlayerTransform = GlobalFuncs.FindPlayerInstance().transform;
     CheckRate       = Random.Range(0.8f, 1.2f);;
 }
예제 #12
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
        }
예제 #13
0
        /// <summary>
        /// Occurs when the new game menu option is clicked.
        /// </summary>
        public void NewGame()
        {
            if (CharacterNameTextBox.text.Length > 2)
            {
                ValidationLabel.text = "";
                if (FirstSceneName.Length > 0)
                {
                    // find the leveling system
                    if (!LevelingSystem)
                    {
                        GameObject player = GlobalFuncs.FindPlayerInstance();
                        if (player)
                        {
                            LevelingSystem = player.GetComponent <CharacterBase>();
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Unable to find player");
                            }
                        }
                    }
                    if (!LevelingSystem)
                    {  // not found?
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("Leveling system not found on player");
                        }
                    }
                    else
                    {  // all good
                        // set the leveling system initial values
                        LevelingSystem.CurrentLevel     = 1;
                        LevelingSystem.Name             = CharacterNameTextBox.text;
                        LevelingSystem.CurrentAxis      = (BaseAxis)AxisDropDown.value;
                        LevelingSystem.CurrentAlignment = (BaseAlignment)AlignDropDown.value;
                        LevelingSystem.CurrentRace      = (BaseRace)RaceDropDown.value;
                        LevelingSystem.CurrentClass     = (BaseClass)ClassDropDown.value;
                        LevelingSystem.ResetToDefaults(); // reset character to the selection
                        LevelingSystem.reCalcCore(true);  // recalc the core stats, max out health etc
                        CharacterNameTextBox.text = "";   // clear for mid game create new character

                        // create a new slot and first save game in the data layer
                        LevelingSystem.SaveSlotID     = 0;
                        LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, FirstSceneName, -1);
                        GlobalFuncs.TheDatabase().ClearInventoryAndHUD();

                        // close the menu and load the scene
#if !VANILLA
                        Inventory.gameObject.SetActive(true);
#endif
                        NewCharacterWindow.SetActive(false);
                        Fader.BeginFade(1);
                        isOpen    = false;
                        lockInput = false;
                        Fader.LoadSceneAsync(FirstSceneName);  // start the load with progress bar
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("First scene name is not specified");
                    }
                }
            }
            else
            {
                ValidationLabel.text = "Missing Character Name..";
            }
        }
예제 #14
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
            }
        }