Esempio n. 1
0
    public BTEnemy(Agent ownerBrain) : base(ownerBrain)
    {
        rootSelector = new Selector();

        enemyCheck          = new Sequence();
        patrolSequence      = new Sequence();
        suspiciousSequence  = new Sequence();
        ChaseSequence       = new Sequence();
        DistractionSequence = new Sequence();

        parallelDetection = new Parallel();
        checkInverter     = new Inverter();

        turnToPoint = new TurnToPoint(GetOwner());
        patrol      = new Patrol(GetOwner());
        wait        = new Wait(GetOwner());

        detection   = new Detection(GetOwner());
        distraction = new Distraction(GetOwner());

        suspicious      = new Suspicious(GetOwner());
        suspiciousAlert = new SuspiciousAlert(GetOwner());
        moveToLKP       = new MoveToLKP(GetOwner());

        seen  = new Seen(GetOwner());
        chase = new Chase(GetOwner());

        //Root -> Patrol and Check
        rootSelector.AddChild(parallelDetection);
        parallelDetection.AddChild(checkInverter);

        //A parallel to check for the player
        checkInverter.AddChild(detection);

        //Patrol alongside checking for the player
        parallelDetection.AddChild(patrolSequence);
        patrolSequence.AddChild(patrol);
        patrolSequence.AddChild(wait);
        patrolSequence.AddChild(turnToPoint);

        //Root -> Adding sequences
        rootSelector.AddChild(suspiciousSequence);
        rootSelector.AddChild(ChaseSequence);
        rootSelector.AddChild(DistractionSequence);

        //Distraction State
        DistractionSequence.AddChild(distraction);
        DistractionSequence.AddChild(wait);

        //Suspicious state
        suspiciousSequence.AddChild(suspicious);
        suspiciousSequence.AddChild(suspiciousAlert);
        suspiciousSequence.AddChild(moveToLKP);
        suspiciousSequence.AddChild(wait);

        //Chase state
        ChaseSequence.AddChild(seen);
        ChaseSequence.AddChild(chase);
        ChaseSequence.AddChild(wait);
    }
Esempio n. 2
0
    public void seeDistraction(Distraction d, Waypoint location)
    {
        if (knownVisualDistractions.Contains(d))
        {
            return;
        }

        distractedBy     = d;
        distractionPoint = location;
        distractionType  = DistractionType.VISUAL;
    }
Esempio n. 3
0
    public void acceptDistraction()
    {
        engageAt(distractionPoint);
        distractionTime = distractedBy.enemyDistractionTime;

        if (distractionType == DistractionType.VISUAL)
        {
            knownVisualDistractions.Add(distractedBy);
        }

        distractedBy     = null;
        distractionPoint = null;
    }
Esempio n. 4
0
    void Update()
    {
        if (Input.GetKeyDown("e") && state)
        {
            if (!GetComponent <Distraction>().isVisualDistraction)
            {
                Distraction d = GetComponent <Distraction>();
                breaking.Play();
                window.GetComponent <Renderer>().material.mainTexture = broken;
//				GetComponent<Renderer>().enabled=false;
                GetComponent <Collider2D>().isTrigger = true;
                d.isVisualDistraction = true;
                d.distract();
            }
        }
    }
Esempio n. 5
0
    public void GoInvestigate(Distraction distraction, bool run)
    {
        if (state != AIState.Patrolling)
        {
            return;
        }

        if (currentDistraction == distraction)
        {
            return;
        }

        currentDistraction = distraction;
        StopAllCoroutines();
        StartCoroutine(Investigate(distraction, run));
    }
Esempio n. 6
0
    private void EnvironmentDetection()
    {
        float stench = 0;
        float noise  = 0;

        RaycastHit2D[] env = Physics2D.CircleCastAll(transform.position, 0.5f, Vector2.up, 1.0f, 1 << LayerMask.NameToLayer("Environment"));
        foreach (RaycastHit2D obj in env)
        {
            Distraction distraction = obj.transform.GetComponent <Distraction>();
            if (distraction != null)
            {
                float dist    = Vector2.Distance(transform.position, distraction.transform.position);
                float falloff = m_Falloff.Evaluate(dist / distraction.radius);
                float output  = distraction.distractionAmount * falloff;

                switch (distraction.distractionType)
                {
                case Distraction.DistractionType.Smell:
                    stench += output;
                    break;

                case Distraction.DistractionType.Noise:
                    noise += output;
                    break;
                }
            }
            else
            {
                Hazard hazard = obj.transform.GetComponent <Hazard>();
                if (hazard != null)
                {
                    float dist    = Vector2.Distance(transform.position, hazard.transform.position);
                    float falloff = m_Falloff.Evaluate(dist / hazard.radius);

                    stench -= hazard.smell * falloff;
                    noise  -= hazard.noise * falloff;
                }
            }
        }

        m_StinkCurrent = stench;
        m_NoiseCurrent = noise;
    }
Esempio n. 7
0
    private IEnumerator Investigate(Distraction distraction, bool run)
    {
        investigating = true;
        cc.Move(0, 0, false, false);
        yield return(new WaitForSeconds(investigationDelay));

        navAgent.SetDestination(distraction.transform.position);

        while (navAgent.pathPending)
        {
            yield return(null);
        }

        var time = investigationDuration;

        while (true)
        {
            OnNavigate(run);

            if (navAgent.remainingDistance < navAgent.stoppingDistance)
            {
                if (time > 0)
                {
                    time -= Time.deltaTime;
                }
                else
                {
                    cc.Move(0, 0, false, false);
                    yield return(new WaitForSeconds(investigationDuration));

                    distraction.Stop();
                    currentDistraction = null;
                    BeginPatrol();
                    investigating = false;
                    break;
                }
            }

            yield return(null);
        }
    }
Esempio n. 8
0
 public bool Equals(Distraction other)
 {
     return(other.gameObject.GetInstanceID() == this.gameObject.GetInstanceID());
 }
 public void Start()
 {
     _player      = FindObjectOfType <PlayerForSillyMonster>();
     _distraction = GetComponent <Distraction>();
 }
Esempio n. 10
0
 public void RemoveDistraction(Distraction d)
 {
     allTheDistractions.Remove(d);
 }
Esempio n. 11
0
 public void AddDistraction(Distraction d)
 {
     allTheDistractions.Add(d);
 }
Esempio n. 12
0
 public void hearDistraction(Distraction d, Waypoint location)
 {
     distractedBy     = d;
     distractionPoint = location;
     distractionType  = DistractionType.SOUND;
 }