Esempio n. 1
0
    public void changeStatus(alertStatus newStatus)
    {
        curState = newStatus;
        //Debug.Log("new state: " + newStatus);
        if (curState == alertStatus.calm)
        {
            audio.playCalm();
            //canAttack = true;
            if (isStationary == true)
            {
                Mtr.setTarget(patrolRoute[0].position);
            }
        }
        else if (newStatus == alertStatus.spotted)
        {
            audio.playSpotted();
            //spotted();
        }
        else if (newStatus == alertStatus.inspect)
        {
            //inspect();
        }
        else if (newStatus == alertStatus.alert)
        {
            if (type == charType.villager)
            {
                //Debug.Log("go to safe zone");
                Mtr.setTarget(SafeZoneWP.getP());
            }

            if (Threat == player)
            {
                Hostile    = true;
                Vis.Layers = HostileMask;
                GetComponentInChildren <SpriteRenderer>().color = new Color(1.0f, 0.5f, 0.5f);
            }
            audio.playAlarm();
            //alert();
        }
        else if (newStatus == alertStatus.flee)
        {
            Mtr.setTarget(SafeZoneWP.getP());
        }
    }
Esempio n. 2
0
    void regenHP()     //flee
    {
        if (Mtr.stuckCheck())
        {
            Debug.Log(name + " ::regenHP stuck");
            Mtr.setTarget(SafeZoneWP.getP());
        }

        if (Health >= 100)
        {
            changeStatus(alertStatus.calm);
        }
        else if (canRegen == true)
        {
            regenCoolDown = Time.time;
            Health++;
            canRegen = false;
        }
        else if (Time.time - regenCoolDown > 0.5)
        {
            canRegen = true;
        }
    }
Esempio n. 3
0
    void alert()
    {
        if (Health <= LowHealth)
        {
            changeStatus(alertStatus.flee);
            return;
        }
        if (type == charType.villager)
        {
            if (((Vector2)Mtr.Trnsfrm.position - Mtr.TargetP).sqrMagnitude < 0.75f)
            {
                if (Time.fixedTime - LSpotted > 5.0f)
                {
                    changeStatus(alertStatus.calm);
                    return;
                }
            }
            if (Mtr.stuckCheck())
            {
                Debug.Log(name + " ::alert_villager stuck");
                Mtr.setTarget(SafeZoneWP.getP());
            }
            //Debug.Log("go to safe zone");
            // Mtr.setTarget(SafeZoneWP.getP());
        }
        else if (type == charType.guard)
        {
            // Debug.Log(" alert " + Threat);
            if (Threat == null || ThreatLevel < -3.0f)
            {
                changeStatus(alertStatus.calm);
                return;
            }

            Mtr.Target = Threat;

            var vec = ((Vector2)Threat.Trnsfrm.position - (Vector2)Mtr.Trnsfrm.position);
            var mag = vec.magnitude; vec /= mag;
            //Debug.Log("mag " + mag + "  dt " + Vector2.Dot(vec, -RotObj.transform.up));
            if (Vector2.Dot(vec, -Mtr.RotObj.transform.up) > 0.8f)
            {
                bool inRange = true;
                foreach (var a in Attacks)
                {
                    if (mag > a.Range)
                    {
                        inRange = false;
                        continue;
                    }
                    if (Time.fixedTime - a.LastAttack > a.Duration + a.RoF)
                    {
                        CurAttack = a;
                        if (Anim != null)
                        {
                            Anim.Play();
                        }
                        a.LastAttack = Time.fixedTime;
                        a.LastTarget = Threat;

                        Vis.enabled = false;
                        break;
                    }
                }
                if (inRange)
                {
                    Mtr.Speed   = 0;
                    Rep.enabled = false;
                }
            }

            if (CurAttack == null && (Time.fixedTime - ShoutTimer > 1.5f))
            {
                LowHealth = 75;

                SortedList <int, AIcontrol> allies = new SortedList <int, AIcontrol>(new DuplicateKeyComparer <int>());
                foreach (var c in Physics2D.OverlapCircleAll(Mtr.Trnsfrm.position, 15, 1 << gameObject.layer))
                {
                    var ai = c.GetComponent <AIcontrol>();
                    if (Threat == player)
                    {
                        ai.check(Threat);
                    }
                    if (ai.type == charType.villager)
                    {
                        continue;
                    }
                    if (ai.curState == alertStatus.calm || (ai.curState == alertStatus.flee && ai.Health > 50))
                    {
                        /*ai.Mtr.setTarget(Mtr.Trnsfrm.position);
                         * ai.changeStatus(alertStatus.assist);
                         * LowHealth = Mathf.Max( 50, LowHealth- 5 );
                         * ai.LowHealth = Mathf.Min( ai.LowHealth, ai.Health );
                         * // Debug.Log("help"); */
                        allies.Add(ai.Health, ai);

                        if (Threat == player)
                        {
                            ai.check(Threat);
                        }
                    }
                    else if (ai.curState == alertStatus.alert)
                    {
                        LowHealth = Mathf.Max(50, LowHealth - 5);
                    }
                }
                //if( allies.Count == 0 ) return;
                //Debug.Log(" allies " + allies.Count );
                foreach (var e in allies)
                {
                    var ai = e.Value;

                    if (ai.Health < LowHealth)
                    {
                        break;
                    }

                    ai.Mtr.setTarget(Mtr.Trnsfrm.position);
                    ai.changeStatus(alertStatus.assist);
                    LowHealth    = Mathf.Max(50, LowHealth - 5);
                    ai.LowHealth = Mathf.Min(ai.LowHealth, LowHealth);
                }
            }

            /*if(canAttack == false) {
             *      if(Time.time - attackTime > attackRateOfFire) {
             *              canAttack = true;
             *      }
             * }
             * //follow and attack player
             * Mtr.setTarget(player.transform.position);
             * if (Vector2.Distance(Mtr.Trnsfrm.position, player.transform.position) <= range && canAttack == true)
             * {
             *      //deal damage
             *      player.GetComponent<PlayerData>().IncreaseHP(Damage);
             *      canAttack = false;
             * }
             */
        }
    }