Ejemplo n.º 1
0
    protected override IEnumerator Execute()
    {
        SetState(NodeState.RUNNING);

        // Fail action if item is out of reach
        if (!senses.IsItemInReach(itemToCollect))
        {
            SetState(NodeState.FAILURE);
            yield break;
        }

        actions.CollectItem(itemToCollect);

        // Check if agent acidentally thinks he picked up item but is not actually in his inventory
        if (!inventory.HasItem(itemToCollect.name.ToString()))
        {
            SetState(NodeState.FAILURE);
            yield break;
        }

        PlayerCache.SetFlagCarriers(itemToCollect);

        SetState(NodeState.SUCCESS);

        yield return(null);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Pick up a collectable item and put it in the inventory
 /// A collected item is no longer visible to other AIs with the exception of the flag
 /// </summary>
 /// <param name="item">The item to pick up</param>
 public void CollectItem(GameObject item)
 {
     if (item != null)
     {
         if (_agentSenses.IsItemInReach(item))
         {
             // If its collectable add it to the inventory
             if (item.GetComponent <Collectable>() != null)
             {
                 item.GetComponent <Collectable>().Collect(_agentData);
                 _agentInventory.AddItem(item);
             }
         }
     }
 }
Ejemplo n.º 4
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);
    }
Ejemplo n.º 5
0
    private void Checks()
    {
        if (_agentInventory.HasItem(Names.HealthKit))
        {
            if (_agentData.CurrentHitPoints <= 50)
            {
                _agentActions.UseItem(_agentInventory.GetItem(Names.HealthKit));
            }
        }

        GameObject ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.HealthKit);

        if (ObjectToCheck != null)
        {
            if (!_agentInventory.HasItem(Names.HealthKit))
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    _agentActions.CollectItem(ObjectToCheck);
                    Simulation((int)nodeOptions);
                }
                else if (Vector3.Distance(transform.position, ObjectToCheck.transform.position) < 7.0f)
                {
                    _agentActions.MoveTo(ObjectToCheck);
                }
            }
        }

        ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.PowerUp);
        if (ObjectToCheck != null)
        {
            if (!_agentInventory.HasItem(Names.PowerUp))
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    _agentActions.CollectItem(ObjectToCheck);
                    Simulation((int)nodeOptions);
                }
                else if (Vector3.Distance(transform.position, ObjectToCheck.transform.position) < 7.0f)
                {
                    _agentActions.MoveTo(ObjectToCheck);
                }
            }
        }

        if (this.tag == Tags.BlueTeam)
        {
            ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.RedFlag);

            if (ObjectToCheck != null)
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    _agentActions.CollectItem(ObjectToCheck);
                    Simulation((int)nodeOptions);
                }
            }

            ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.BlueFlag);

            if (ObjectToCheck != null)
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    ObjectToCheck.GetComponent <Flag>().ResetPositionBlue();
                    Simulation((int)nodeOptions);
                }
            }

            if (_agentData.HasEnemyFlag)
            {
                if (Vector3.Distance(transform.position, _agentData.FriendlyBase.transform.position) <= 5.0f)
                {
                    _agentActions.DropItem(_agentInventory.GetItem(Names.RedFlag));
                    hasWon = true;
                    ResetPosition();
                    hasWon      = false;
                    currentNode = rootNode;
                    Debug.Log("win" + this.gameObject);
                }
            }
        }

        if (this.tag == Tags.RedTeam)
        {
            ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.BlueFlag);

            if (ObjectToCheck != null)
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    _agentActions.CollectItem(ObjectToCheck);
                    Simulation((int)nodeOptions);
                }
            }

            ObjectToCheck = _agentSenses.GetObjectInViewByName(Names.RedFlag);

            if (ObjectToCheck != null)
            {
                if (_agentSenses.IsItemInReach(ObjectToCheck))
                {
                    ObjectToCheck.GetComponent <Flag>().ResetPositionRed();
                    Simulation((int)nodeOptions);
                }
            }

            if (_agentData.HasEnemyFlag)
            {
                if (Vector3.Distance(transform.position, _agentData.FriendlyBase.transform.position) <= 5.0f)
                {
                    _agentActions.DropItem(_agentInventory.GetItem(Names.BlueFlag));
                    hasWon = true;
                    ResetPosition();
                    hasWon = false;
                    Debug.Log("win" + this.gameObject);
                }
            }
        }
    }