Example #1
0
    public void initialize()
    {
        blurIteration_ = blur_.blurIterations;
        blurSpread_    = blur_.blurSize;
        mainCameraPos_ = camera_.transform.position;
        mainCameraRot_ = camera_.transform.rotation;

        state_ = new State_Idle(this);
    }
Example #2
0
 protected override void Start()
 {
     base.Start();
     fleeState = new State_Flee(this, mask);
     fleeState.NoLongerFleeing += Idle;
     idleState = new State_Idle(this);
     idleState.TargetSpotted += Flee;
     BehaviourState           = idleState;
 }
Example #3
0
 protected override void Start()
 {
     base.Start();
     canPickupTreasure        = true;
     followState              = new State_Follow(this, Leader);
     idleState                = new State_Idle(this);
     idleState.TargetSpotted += DecisionTree;
     if (isFollowing)
     {
         FollowLeader();
     }
     else
     {
         BehaviourState = idleState;
         pursuitRange   = 50f;
     }
 }
Example #4
0
    protected virtual void Awake()
    {
        myRigidbody = GetComponent <Rigidbody2D>();

        //Animation
        myAnimator = GetComponent <Animator>();


        //State
        attackState       = GetComponent <State_Attack>();
        deathState        = GetComponent <State_Death>();
        dodgeState        = GetComponent <State_Dodge>();
        guardState        = GetComponent <State_Guard>();
        hitState          = GetComponent <State_Hit>();
        idleState         = GetComponent <State_Idle>();
        moveState         = GetComponent <State_Move>();
        battle_idleState  = GetComponent <State_Battle_Idle>();
        skillUseState     = GetComponent <State_SkillUse>();
        targetSearchState = GetComponent <State_TargetSearch>();
    }
Example #5
0
 private void Awake()
 {
     m_curState = new State_Idle();
 }
Example #6
0
    void Start()
    {
        hpDesire     = 0;
        hpStatus     = 0;
        weaponDesire = 0;
        powerful     = 0;
        agent        = GetComponentInParent <Agent>();
        vehicle      = GetComponentInParent <Vehicle>();
        GameObject[] tempallies = GameObject.FindGameObjectsWithTag("Enemy_AI");

        for (int i = 0; i < tempallies.Length; i++)
        {
            allies.Add(tempallies[i]);
        }
        for (int i = 0; i < allies.Count; i++)
        {
            if (allies[i] == agent.gameObject)
            {
                allies.Remove(allies[i]);
            }
        }
        if (allies.Count > 0)
        {
            hasBeenFoundDead.Capacity = allies.Count;
            Debug.Log(allies.Count);
            for (int i = 0; i < hasBeenFoundDead.Capacity; i++)
            {
                hasBeenFoundDead.Add(false);
            }
        }
        if (isRoaming)
        {
            wanderDesire = 0.1f;
            postDesire   = 0f;
            State_Patrol patrolState = new State_Patrol();
            agent.ChangeState(patrolState);
        }
        else
        {
            wanderDesire = 0f;
            postDesire   = 0.1f;
            Debug.Log("is it here?");
            State_Idle idleState = new State_Idle();
            agent.ChangeState(idleState);
        }
        switch (Personality)
        {
        case 0:     //the cowardly unit
            fightModifier = 0.7f;
            runModifier   = 1.3f;
            break;

        case 1:     //the regular unit that does not have edited values
            fightModifier = 1f;
            runModifier   = 1f;
            break;

        case 2:
            fightModifier = 1.5f;
            runModifier   = 0.7f;
            break;
        }
    }
Example #7
0
    void Update()
    {
        if (agent.gameObject.GetComponent <Perception>().MemoryMap.ContainsKey(player))
        {
            timeSinceSeen = DateTime.Now - agent.gameObject.GetComponent <Perception>().MemoryMap[player].TimeLastSensed;
        }
        else
        {
            powerful = 0; //if the player has never been seen then the power is set to 0 by default to stop it from wanting to fight something it doesn't know exists
        }
        for (int i = 0; i < allies.Count; i++)
        {
            if (hasBeenFoundDead[i] == false)
            {
                if (agent.gameObject.GetComponent <Perception>().MemoryMap.ContainsKey(allies[i]))
                {
                    if (agent.gameObject.GetComponent <Perception>().MemoryMap[allies[i]].targetDead == true)
                    {
                        deadAllyCounter    += 0.1f;
                        hasBeenFoundDead[i] = true;
                    }
                }
            }
        }

        List <float> desireList = new List <float>();

        desireList.Add(weaponDesire);
        desireList.Add(hpDesire);
        desireList.Add(powerful);
        desireList.Add(wanderDesire);
        desireList.Add(postDesire);

        if (timeSinceSeen.Seconds > timeToForget)
        {
            powerful = 0; //if the unit has not seen the player in 50 seconds the power will be set to 0
        }


        if (desireList.Max() == powerful)
        {
            if (agent.gameObject.GetComponent <Perception>().MemoryMap != null && agent.gameObject.GetComponent <Perception>().MemoryMap.ContainsKey(player) && agent.gameObject.GetComponent <Perception>().MemoryMap[player].WithinFoV == false)
            {
                //if the powerful state has the highest desirability and the AI cannot see the player, the AI will search for the player
                if (Search_State_On == false)
                {
                    State_Search_Player pSearchState = new State_Search_Player();
                    ResetBools();
                    Search_State_On = true;
                    agent.ChangeState(pSearchState);
                }
            }
            else if (agent.gameObject.GetComponent <Perception>().MemoryMap != null && agent.gameObject.GetComponent <Perception>().MemoryMap.ContainsKey(player) && agent.gameObject.GetComponent <Perception>().MemoryMap[player].WithinFoV == true)
            {
                if (player.GetComponent <Player_Gun>().playerPower <= powerful) //checks to see how strong the player is compared to the unit - will make them flee if they feel weaker in comparison
                {
                    if (Vector3.Distance(agent.transform.position, player.transform.position) > agent.fireRange)
                    {
                        if (Search_State_On == false)
                        {
                            State_Search_Player pSearchState = new State_Search_Player();
                            ResetBools();
                            Search_State_On = true;
                            agent.ChangeState(pSearchState);
                        }
                    }
                    else
                    {
                        if (Fight_State_On == false)
                        {
                            State_Fight_Player fightState = new State_Fight_Player();
                            ResetBools();
                            Fight_State_On = true;
                            agent.ChangeState(fightState);
                        }
                    }
                }
                else if (player.GetComponent <Player_Gun>().playerPower > powerful)
                {
                    Debug.Log("Epic");
                    if (Flee_State_On == false)
                    {
                        State_Flee fleeState = new State_Flee();
                        ResetBools();
                        Flee_State_On = true;
                        agent.ChangeState(fleeState);
                    }
                }
            }
        }
        if (desireList.Max() == weaponDesire)
        {
            //if the desire to find ammo is the highest it will try to find ammo
            if (Ammo_State_On == false)
            {
                State_Search_Ammo ammoState = new State_Search_Ammo();
                ammoState.hasCreatedPath = false;
                ResetBools();
                Ammo_State_On = true;
                agent.ChangeState(ammoState);
            }
        }
        if (desireList.Max() == hpDesire)
        {
            //if the desire to find health is the highest it will try to find health
            if (HP_State_On == false)
            {
                State_Search_Health healthState = new State_Search_Health();
                healthState.hasCreatedHealthPath = false;
                ResetBools();
                HP_State_On = true;
                agent.ChangeState(healthState);
            }
        }
        if (desireList.Max() == wanderDesire)
        {
            State_Patrol patrolState = new State_Patrol();
            agent.ChangeState(patrolState);
        }
        if (desireList.Max() == postDesire)
        {
            if (Vector3.Distance(transform.position, postLocation) < 5f)
            {
                agent.SB.IsSeekOn = false;
                State_Idle idleState = new State_Idle();
                agent.ChangeState(idleState);
            }
            else
            {
                if (Post_State_On == false)
                {
                    State_Return_To_Post postState = new State_Return_To_Post();
                    ResetBools();
                    Post_State_On = true;
                    agent.ChangeState(postState);
                }
            }
        }
    }