Beispiel #1
0
    //this is a function that looks for the flag and checks to see if it is within thier home base
    public bool CheckflagAtBase(Sensing sense, AgentData data, GameObject FriendBase)
    {
        //gets a list of the items within view
        List <GameObject> temp = new List <GameObject>();

        //finds all items with the flag tag
        foreach (GameObject g in sense.GetObjectsInViewByTag("Flag"))
        {
            temp.Add(g);
        }

        for (int i = 0; i < temp.Count; ++i)
        {
            if (temp[i].name == data.EnemyFlagName)
            {
                Debug.Log("Found Flag");
                if (temp[i].transform.position.x == FriendBase.transform.position.x || (temp[i].transform.position.x == FriendBase.transform.position.x - 50) || (temp[i].transform.position.x == FriendBase.transform.position.x + 50))
                {
                    return(true);
                }
            }
        }


        return(false);
    }
Beispiel #2
0
    // a function that allows the enemy to move towards the powerup if they see it and if they are within range they will be able to use the power up
    public bool FindPowerUp(Sensing sense, AgentData data, AgentActions actions, bool PowerUpZone)
    {
        List <GameObject> objects = sense.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Power Up")
            {
                if (sense.IsItemInReach(objects[i]))
                {
                    objects[i].GetComponent <PowerUp>().Use(data);
                }
            }
        }

        if (!PowerUpZone)
        {
            if (data.FriendlyTeamTag == Tags.BlueTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("Powerup"));
            }
            else if (data.FriendlyTeamTag == Tags.RedTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("Powerup"));
            }
        }

        return(true);
    }
Beispiel #3
0
    // a function that once the Ai becomes low on health they will begin to move away from the fight and is they see the health kit within view then they will use it
    public bool Fleeing(AgentActions actions, AgentData data, Sensing sensing, bool HealthZone)
    {
        List <GameObject> objects = sensing.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Health Kit")
            {
                objects[i].GetComponent <HealthKit>().Use(data);
            }
        }

        if (!HealthZone)
        {
            if (data.FriendlyTeamTag == Tags.BlueTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("HealthKit"));
            }
            else if (data.FriendlyTeamTag == Tags.RedTeam)
            {
                actions.MoveTo(GameObject.FindGameObjectWithTag("HealthKit"));
            }
        }



        return(true);
    }
 public CollectItem(AgentActions actions, Sensing senses, InventoryController inventory, GameObject itemToCollect)
 {
     this.actions       = actions;
     this.senses        = senses;
     this.inventory     = inventory;
     this.itemToCollect = itemToCollect;
 }
    public AttackNearbyEnemy(AgentActions actions, Sensing senses, float attackDelay)
    {
        this.actions = actions;
        this.senses  = senses;

        attackTimer = new WaitForSeconds(attackDelay);
    }
Beispiel #6
0
 // Use this for initialization
 void Start()
 {
     // Initialise the accessable script components
     _agentData      = GetComponent <AgentData>();
     _agentActions   = GetComponent <AgentActions>();
     _agentSenses    = GetComponentInChildren <Sensing>();
     _agentInventory = GetComponentInChildren <InventoryController>();
 }
Beispiel #7
0
 // Use this for initialization, get references to all the component scripts we'll need
 void Start()
 {
     _agentData          = GetComponent <AgentData>();
     _agentSenses        = GetComponentInChildren <Sensing>();
     _agentInventory     = GetComponentInChildren <InventoryController>();
     _navAgent           = GetComponent <UnityEngine.AI.NavMeshAgent>();
     _swordAnimator      = GetComponentInChildren <Animator>();
     _agentMoodIndicator = GetComponentInChildren <AiMoodIconController>();
 }
Beispiel #8
0
 // Use this for initialization
 void Start()
 {
     // Initialise the accessable script components
     _agentData      = GetComponent <AgentData>();
     _agentActions   = GetComponent <AgentActions>();
     _agentSenses    = GetComponentInChildren <Sensing>();
     _agentInventory = GetComponentInChildren <InventoryController>();
     currentNode     = rootNode;
     startingPostion = transform.position;
     // nodeOptions = NodeOptions.Nothing;
 }
Beispiel #9
0
 // a function that checks to see if the Ai has low health and if they do they will begin to flee
 public bool LowHealth(AgentData data, AgentActions actions, Sensing sensing, bool Retreated, bool HealthZone)
 {
     if (data.CurrentHitPoints < 15)
     {
         if (sensing.GetEnemiesInView().Count == 0)
         {
             Fleeing(actions, data, sensing, HealthZone);
             return(true);
         }
     }
     return(false);
 }
Beispiel #10
0
    void Start()
    {
        // Initialise the accessable script components
        _agentData      = GetComponent <AgentData>();
        _agentActions   = GetComponent <AgentActions>();
        _agentSenses    = GetComponentInChildren <Sensing>();
        _agentInventory = GetComponentInChildren <InventoryController>();


        StateMachine = new StateMachineController <AI>(this);  //Creates a state machine for this AI Agent
        StateMachine.ChangeState(GotoEnemyBaseState.Instance); //Set the initial state of the AI Player
    }
Beispiel #11
0
    // a function that allows the Ai to check to see if there are enemys near by. if there are then they will begin to move to wards them and attack. slowing down when they get close enough to attack
    public void Attack(Sensing view, AgentActions action)
    {
        //first see if an enemy comes into view
        foreach (GameObject G in view.GetEnemiesInView())
        {
            action.ResumeMovement();
            action.MoveTo(G);
            action.AttackEnemy(G);
            //this.GetComponent<AgentActions>().AttackEnemy(G);
        }

        //need to resume movement when enemyes are dead
    }
Beispiel #12
0
    // Use this for initialization
    public virtual void Start()
    {
        // Initialise the accessable script components
        _agentData      = GetComponent <AgentData>();
        _agentActions   = GetComponent <AgentActions>();
        _agentSenses    = GetComponentInChildren <Sensing>();
        _agentInventory = GetComponentInChildren <InventoryController>();

        enemyFlag    = GameObject.Find(flag.ToString() + " Flag");
        friendlyFlag = GameObject.Find(getData().FriendlyFlagName);
        Base         = GameObject.Find(baseEnum.ToString() + " Base");
        agent        = GetComponent <NavMeshAgent>();
        powerup      = GameObject.Find("Power Up");
        health       = GameObject.Find("Health Kit");
        defencePoint = transform.position;
    }
Beispiel #13
0
    //if the AI does not have the flag it finds all tema mates and finds which ever one has the glag
    public bool ProtectTeamMate(Sensing sense, AgentData data, AgentActions actions)
    {
        List <GameObject> TeamMembers;

        TeamMembers = sense.GetFriendliesInView();

        if (!data.HasEnemyFlag)
        {
            foreach (GameObject G in TeamMembers)
            {
                if (G.GetComponent <AgentData>().HasEnemyFlag)
                {
                    actions.MoveTo(G);
                }
            }
        }

        return(true);
    }
Beispiel #14
0
    // a function that allows the ai to pick up a flag if they are close enough and see it within view
    public bool PickUpFlag(Sensing sight, AgentActions actions, AgentData data)
    {
        List <GameObject> temp = new List <GameObject>();

        foreach (GameObject g in sight.GetObjectsInViewByTag("Flag"))
        {
            temp.Add(g);
        }

        for (int i = 0; i < temp.Count; ++i)
        {
            if (temp[i].name == "Red Flag") //checks to make sure the item within range is the red flag
            {
                if (data.FriendlyTeamTag == Tags.BlueTeam)
                {
                    //when the Ai is within view distance
                    actions.MoveTo(temp[i]);
                    // then it collects the item
                    actions.CollectItem(temp[i]);
                }
            }
            else if (temp[i].name == "Blue Flag") //checks to make sure the item within range is the blue flag
            {
                if (data.FriendlyTeamTag == Tags.RedTeam)
                {
                    //when the Ai is within view distance
                    actions.MoveTo(temp[i]);
                    // then it collects the item
                    actions.CollectItem(temp[i]);
                }
            }
        }

        if (data.HasEnemyFlag)
        {
            return(true);
        }



        return(false);
    }
Beispiel #15
0
    // a function that gets the ai to try and get thier own flag back and return it to thier base
    public bool RetrieveFlag(Sensing sight, AgentActions actions, AgentData data, AI theai)
    {
        List <GameObject> Temp = new List <GameObject>();

        foreach (GameObject G in sight.GetObjectsInViewByTag("Flag"))
        {
            Temp.Add(G);
        }

        for (int i = 0; i < Temp.Count; ++i)
        {
            if (Temp[i].name == "Red Flag") //checks to make sure the item within range is the red flag
            {
                if (data.FriendlyTeamTag == "Red Team")
                {
                    //when the Ai is within view distance
                    actions.MoveTo(Temp[i]);
                    // then it collects the item
                    actions.CollectItem(Temp[i]);
                }
            }
            else if (Temp[i].name == "Blue Flag") //checks to make sure the item within range is the blue flag
            {
                if (data.FriendlyTeamTag == "Blue Team")
                {
                    //when the Ai is within view distance
                    actions.MoveTo(Temp[i]);
                    // then it collects the item
                    actions.CollectItem(Temp[i]);
                }
            }
        }

        if (data.HasFriendlyFlag)
        {
            theai.GotFriendlyFlag = true;
        }

        return(true);
    }
Beispiel #16
0
    // a function that checks all objects in view and trys to find all of them that are classified as an enemy
    public bool FindEnemyflag(Sensing sight, AgentData data)
    {
        //gets a list of the items within view
        List <GameObject> temp = new List <GameObject>();

        //finds all items with the flag tag
        foreach (GameObject g in sight.GetObjectsInViewByTag("Flag"))
        {
            temp.Add(g);
        }

        for (int i = 0; i < temp.Count; ++i)
        {
            if (temp[i].name == data.EnemyFlagName)
            {
                return(true);
            }
        }


        return(false);
    }
Beispiel #17
0
    // Use this for initialization
    void Start()
    {
        // Initialise the accessable script components
        _agentData      = GetComponent <AgentData>();
        _agentActions   = GetComponent <AgentActions>();
        _agentSenses    = GetComponentInChildren <Sensing>();
        _agentInventory = GetComponentInChildren <InventoryController>();

        //actions = GetComponent<Actions>();
        Retreated = false;

        if (_agentData.FriendlyTeamTag == "Blue Team")
        {
            FreindlyGuardSpotTwo = GameObject.FindGameObjectWithTag("BlueGuardSpotTwo");
            FriendlyGuardSpotOne = GameObject.FindGameObjectWithTag("BlueGuardSpotOne");
        }
        else
        {
            FreindlyGuardSpotTwo = GameObject.FindGameObjectWithTag("RedGuardSpotTwo");
            FriendlyGuardSpotOne = GameObject.FindGameObjectWithTag("RedGuardSpotOne");
        }
    }
Beispiel #18
0
    //a function that allowed the AI to guard their base when they had both of thier flags within the base
    public bool Gaurd(AgentActions actions, Sensing sensing, AgentData data, GameObject HomeBase, GameObject GuardSpotOne, GameObject GuardSpotTwo, int GuardSpotNumber)
    {
        //move home
        MoveHome(actions, HomeBase);

        actions.DropAllItems();

        // if there are any enemies within view then they need to attack the enemy
        Attack(sensing, actions);

        if (GuardSpotNumber == 1)
        {
            //might want to change this so that it move between two spots every time the function is called to act more like a gaurding Ai
            actions.MoveTo(GuardSpotOne);
        }
        else if (GuardSpotNumber == 2)
        {
            actions.MoveTo(GuardSpotTwo);
        }

        return(true);
    }
Beispiel #19
0
    // a function that allows the aI to be able to find the health kit and if it is within reach range then the ai will use it. if not they will then begin to move up to it
    public bool FindHealthKit(AgentActions actions, Sensing sensing, AgentData data, GameObject HealthZone)
    {
        actions.MoveTo(HealthZone);
        //actions.PauseMovement();


        // need to make this so that it only uses move to random once so it can actually move

        List <GameObject> objects = sensing.GetCollectablesInView();

        for (int i = 0; i < objects.Count; i++)
        {
            if (objects[i].name == "Health Kit")
            {
                if (sensing.IsItemInReach(objects[i]))
                {
                    objects[i].GetComponent <HealthKit>().Use(data);
                }
            }
        }

        return(true);
    }
 public IsItemInView(Sensing senses, GameObject itemToCheck)
 {
     this.senses      = senses;
     this.itemToCheck = itemToCheck;
 }
Beispiel #21
0
 public IsEnemyInSight(Sensing senses)
 {
     this.senses = senses;
 }