Beispiel #1
0
    void Start()
    {
        _rigidbody    = GetComponent <Rigidbody>();
        _navMeshAgent = GetComponent <NavMeshAgent>();
        _unitStats    = GetComponent <UnitStats>();
        _aiManager    = GameObject.FindGameObjectWithTag("Manager").GetComponent <AIManager>();

        _navMeshAgent.avoidancePriority = Random.Range(1, 98);

        teamIndex = Random.Range(1, 3);


        _class      = _aiManager.GetClass();
        health      = _class.Health;
        respawnTime = _class.RespawnTime;


        if (teamIndex == 1)
        {
            foreach (SkinnedMeshRenderer MR in _skinnedMeshRenderer)
            {
                MR.material = goodMaterial;
            }
        }
        else
        {
            foreach (SkinnedMeshRenderer MR in _skinnedMeshRenderer)
            {
                MR.material = badMaterial;
            }
        }

        StartCoroutine(Loop());
    }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     aiInteract = GetComponent <AIInteract>();
     aiClass    = GetComponent <AIClass>();
     target     = null;
     distance   = 0.0f;
     turnSpeed  = 5f;
 }
Beispiel #3
0
 // Use this for initialization
 void Start()
 {
     aiClass    = GetComponent <AIClass>();
     aiFight    = GetComponent <AIFight>();
     aiMovement = GetComponent <AIMovement>();
     aiInteract = GetComponent <AIInteract>();
     CheckJob();
     GameController.gameController.questControl.GenerateQuest(job, this);
 }
 // Use this for initialization
 void Start()
 {
     aiClass         = GetComponent <AIClass>();
     playerMovements = GetComponent <PlayerMovements>();
     playerInteract  = GetComponent <PlayerInteract>();
     animator        = GetComponentInChildren <Animator>();
     hpBar           = GameObject.FindWithTag("BattleUI").transform.GetChild(0);
     maxHP           = hp;
     BattleUI.battleUI.playerFight = this;
 }
 // Update is called once per frame
 void FixedUpdate()
 {
     if (!playerInventory)
     {
         playerInventory = BattleUI.battleUI.playerInventory;
     }
     if (!playerClass)
     {
         playerClass = BattleUI.battleUI.playerClass;
     }
     if (!itemPrefab)
     {
         itemPrefab = ItemCollection.itemCollection.itemPrefab;
     }
 }
Beispiel #6
0
    void Start()
    {
        aiClass        = transform.parent.parent.GetComponent <AIClass>();
        aiMovement     = transform.parent.parent.GetComponent <AIMovement>();
        playerMovement = transform.parent.parent.GetComponent <PlayerMovements>();
        aiFight        = transform.parent.parent.GetComponent <AIFight>();
        animator       = transform.parent.parent.GetComponent <Animator>();
        mainHand       = transform.parent.transform;
        body           = mainHand.parent.transform;


        attacking = false;
        distance  = 0f;


        CheckType();
    }
Beispiel #7
0
    //Focus on player
    IEnumerator VFocusState()
    {
        Transform target = GameObject.FindWithTag ("Player").transform;
        while (viewState == ViewState.VFocus)
        {
            //Vision Cone calculation
            Vector3 targetDir = target.position - transform.position;
            Vector3 forward = transform.forward;
            float angle = Vector3.Angle(targetDir, forward);
            if (angle > visionAngle)
                viewState = ViewState.VIdle;
            else
            {
                RaycastHit hit;
                //Check if there are any objects in the way
                if (Physics.Raycast(transform.position, targetDir, out hit))
                {
                    if(hit.transform == target)
                    {
                        //Tell other AI where player is
                        GameObject[] objArray = GameObject.FindGameObjectsWithTag ("Enemy");
                        AIClass[] enemyArray = new AIClass[objArray.Length];
                        for(int i = 0; i < enemyArray.Length; i++)
                        {

                            enemyArray[i] = (AIClass)objArray[i].GetComponent(typeof(AIClass));
                            if(i >= enemyArray.Length/2)
                            {
                                //Debug.Log ("AI: I see him!");
                                enemyArray[i].agent.destination = target.position;
                            }
                            else if(!flee)
                                enemyArray[i].agent.destination = target.position + target.forward*5;
                            enemyArray[i].movementState = MovementState.MSearch;

                        }
                        seesPlayer = true;
                        transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(target.position - transform.position), vRotationSpeed*Time.deltaTime);
                        //Check to see player is within sights of the gun
                        if (angle < firingAngle)
                        {
                            //Debug.Log ("AI: Got him in my sights!");
                            isFocusedOnPlayer = true;
                        }
                        else
                            isFocusedOnPlayer = false;
                    }
                    else
                    {
                        //I no longer see the player
                        //Debug.Log ("AI: Sorry guys, no longer got him");
                        seesPlayer = false;
                        viewState = ViewState.VIdle;
                        isFocusedOnPlayer = false;
                    }
                }
            }
            yield return 0;
        }
                        NextViewState ();
    }
 void CreateObjects()
 {
     P1 = new PlayerClass(X_Piece, p1Shape);
     if(AIflag) {
         if(AIlevel == 0) {
             P2 = new AIClass(O_Piece, p2Shape);
         }
         else if (AIlevel == 1) {
             P2 = new AIMediumClass(O_Piece, p2Shape);
         }
         else if (AIlevel == 2) {
             P2 = new AIHardClass(O_Piece, p2Shape);
         }
     }
     else {
         P2 = new PlayerClass(O_Piece, p2Shape); }
 }
 // Use this for initialization
 void Start()
 {
     playerInventory = BattleUI.battleUI.playerInventory;
     playerClass     = BattleUI.battleUI.playerClass;
     itemPrefab      = ItemCollection.itemCollection.itemPrefab;
 }
 // Use this for initialization
 void Start()
 {
     a = GameObject.Find("Enemy").GetComponent<AIClass>();
 }
    private AIClass getBestMove(int[] tempBoard, int player, int depth)
    {
        // fail-safe (I thought)
        if (depth >= 8)
        {
            return(new AIClass(0));
        }
        // base case, check for end state
        if (WinnerCheck(tempBoard) == aiPlayer + 1) // ai wins
        {
            return(new AIClass(10));
        }
        else if (WinnerCheck(tempBoard) == humanPlayer + 1) // human wins
        {
            return(new AIClass(-10));
        }
        else if (WinnerCheck(tempBoard) == 0) // draw
        {
            Debug.Log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            return(new AIClass(0));
        }

        List <AIClass> moveList = new List <AIClass>();

        // for every tile in the grid that isn't occupied, make a move
        for (int i = 0; i < tempBoard.Length; i++)
        {
            if (depth == 0)
            {
                Debug.Log("Board index: " + i);
            }
            if (tempBoard[i] == (int)gridValue.NO_VAL)
            {
                AIClass newMove = new AIClass();
                newMove.movePosition = i;

                tempBoard[i] = player + 1;

                // if we are the AI, we want to get the score of the next move the human would make
                if (player == aiPlayer)
                {
                    //Debug.Log("AI player places at index " + i);
                    newMove.score = getBestMove(tempBoard, humanPlayer, depth + 1).score;
                }
                else // get the score of the next move that the AI would make
                {
                    //Debug.Log("Human player palces at index " + i);
                    newMove.score = getBestMove(tempBoard, aiPlayer, depth + 1).score;
                }

                moveList.Add(newMove);
                if (depth == 0)
                {
                    Debug.Log("Adding move of score " + newMove.score + ". New length: " + moveList.Count);
                }
                tempBoard[i] = (int)gridValue.NO_VAL;
            }
        }

        // get the best move possible from the recursion
        int bestMove = 0;

        // ai will always take the biggest score
        if (player == aiPlayer)
        {
            int bestScore = -1000000; // we start with an extreme number so we ensure that we move in the correct direction
                                      //  in this condition we want to get a larger score
            for (int i = 0; i < moveList.Count; i++)
            {
                if (moveList[i].score > bestScore)
                {
                    bestMove  = i;
                    bestScore = moveList[i].score;
                }
            }
        }
        else // the player will always take the lowest score
        {
            int bestScore = 1000000;
            for (int i = 0; i < moveList.Count; i++)
            {
                if (moveList[i].score < bestScore)
                {
                    bestMove  = i;
                    bestScore = moveList[i].score;
                }
            }
        }
        if (depth == 0)
        {
            Debug.Log("Move index: " + bestMove + " length of move array " + moveList.Count);
        }
        Debug.Log("Depth: " + depth);
        return(moveList[bestMove]);
    }