void InPen()
    {
        if (inPen)
        {
            if (sheepState != SheepState.Sheep_In_Pen)
            {
                placid      = false;
                placidSheep = 0f;
            }
            currentMoveTimer = 0f;
            sheepState       = SheepState.Sheep_In_Pen;
            placidSheep     += Time.deltaTime;
            if (placidSheep >= 3f)
            {
                RandomPositionTimer();
                placid = true;
            }

            if (placid)
            {
            }

            if ((Vector2.Distance(transform.position, pen.position) > 0.1f) && !placid)
            {
                currentDirection = (pen.position - transform.position).normalized;
            }
        }
    }
Exemplo n.º 2
0
 private void CheckSheepFollower(HerdSheepBase target)          //부딪힌 오브젝트에 HerdSheepBase가 존재할시 행동.
 {
     //양에 주인이 없을 경우.
     if (SS.Equals(SheepState.NOOWNER))
     {
         this.follower = target;
         SS            = SheepState.HAVEOWNER;
         target.AddSheepList(this);
         ManagerHandler.Instance.GameManager().FromHordeSheepToOwneredSheep(this);
     }
     //양에게 주인이 있을경우 능동성 및 마스터 여부를 따져서 행동한다.
     else if (SS.Equals(SheepState.HAVEOWNER))
     {
         // Equals는 대상의 내용, ==는 대상의 주소를 비교한다.
         if (target.GetOwner() == this.follower.GetOwner())
         {
             //주인이 같은경우 행동하지 않는다.
             return;
         }
         else
         {
             if (!target.isTakeOverPermit())
             {
                 //주인이 다르나 탈취 권한이 없을경우 역시 행동하지 않는다.
             }
             else
             {
                 //주인도 다르고 탈취 권환도 있을경우 행동.
                 this.follower.ChangeMasterToTargetOwner(this, target);
             }
         }
     }
 }
    //Add potential for the sheep to escape. After a set time, or if the player is within scare distance
    void JailbreakPlanning()
    {
        //check if initial time, guaranteed no escape
        if (cantEscapeTimer < cantEscapeTime)
        {
            cantEscapeTimer += Time.deltaTime;
        }
        cantEscapeTimer = Mathf.Clamp(cantEscapeTimer, 0, cantEscapeTime);
        //start increasing a chance for the sheep to escape
        if (cantEscapeTimer >= cantEscapeTime)
        {
            currentEscapeChance = Mathf.InverseLerp(0f, escapeDecayTime, maybeEscapesTimer);
            maybeEscapesTimer  += Time.deltaTime;
            escapeCheckNumber   = Random.Range(0, 1000) / 10.0f;
        }
        //check to see if they escape. checking a random number against being under the currentEscapeChance

        if (escapeCheckNumber <= (Mathf.Round(currentEscapeChance * 10f) / 10f))
        {
            cantEscapeTimer     = 0;
            escapeCheckNumber   = 100;
            maybeEscapesTimer   = 0;
            currentEscapeChance = 0;
            sheepState          = SheepState.Sheep_Escaping;
        }
    }
Exemplo n.º 4
0
 public void SetSheepState(SheepState state)
 {
     foreach (var sheep in botSheeps)
     {
         sheep.State.SetState(state);
     }
 }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (mIsDead)
        {
            return;
        }
        if (!canMove)
        {
            mAIAgent.maxSpeed = 0;
        }
        else
        {
            //mAIAgent.canMove = true;
            mAIAgent.maxSpeed = 4;
        }

        sqrtDistance            = (transform.position - Player.transform.position).sqrMagnitude;
        enemyDistanceAttackSqrt = EnemyDistanceAttack * EnemyDistanceAttack;

        float EnemyDistanceChaseSqrt = EnemyDistanceChase * EnemyDistanceChase;

        if (sqrtDistance < EnemyDistanceChaseSqrt && isAttackFinish)
        {
            State = SheepState.Chase;
            if (sqrtDistance <= enemyDistanceAttackSqrt)
            {
                State = SheepState.Attack;
            }
        }
        if (sqrtDistance >= EnemyDistanceChaseSqrt && isAttackFinish)
        {
            State = SheepState.Patrol;
        }

        switch (State)
        {
        case SheepState.Idle:
            return;

        case SheepState.Chase:
            mAnimator.SetBool("isWalking", IsNavMeshMoving);
            Chase();
            return;

        case SheepState.Attack:
            mAnimator.SetBool("isWalking", false);
            mAnimator.SetBool("isAttacking", IsAttacking);
            OnAttack();    //hp down
            return;

        case SheepState.Patrol:
            mAnimator.SetBool("isWalking", IsNavMeshMoving);
            OnPatrol();
            return;

        default:
            break;
        }
    }
Exemplo n.º 6
0
 private void _RunningState()
 {
     if (_HasFlag(_CurrentAction, EAction.Jump))
     {
         _Jump(JumpForce);
         _CurrentState = SheepState.Jumping;
     }
 }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     _CurrentState = SheepState.Running;
     for (int i = 0; i < InputFramesDelay; i++)
     {
         _Inputs.Enqueue(0);
     }
 }
Exemplo n.º 8
0
 private void OnStateChanged(SheepState state)
 {
     if (state == SheepState.Death)
     {
         OnDeath?.Invoke(this);
         isDead = true;
     }
 }
Exemplo n.º 9
0
 protected override void OnStateChanged(SheepState state)
 {
     if (state.Equals(SheepState.Walk))
     {
         var rotation = Quaternion.Euler(0f, Random.Range(0, 360), 0f);
         transform.DORotate(rotation.eulerAngles, turnDuration);
     }
 }
Exemplo n.º 10
0
 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         _currentState = SheepState.AFRAID;
         return;
     }
 }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        //Determine the next position

        switch (sheepState)
        {
        case SheepState.Sheep_Wander:
            //Check to see if the player is in our Zone of influence
            PlayerVisible();
            //If none of that has happened, we'll just check to randomly change our direction
            RandomPositionTimer();
            //Check to see if we're in the pen
            InPen();
            break;

        case SheepState.Sheep_Avoid:
            //Check to see if the player is in our Zone of influence
            PlayerVisible();
            //Check to see if we're in the pen
            InPen();
            break;

        case SheepState.Sheep_Barked:
            //Sheep has been barked at, keep moving until we're done
            moveSpeed = barkAvoidSpeed;
            if (lastBarkTime >= barkTimer)
            {
                //Done avoiding the bark
                moveSpeed  = originalMoveSpeed;
                sheepState = SheepState.Sheep_Wander;
            }
            else
            {
                lastBarkTime += Time.deltaTime;
            }
            break;

        case SheepState.Sheep_In_Pen:
            //Check to see if we're in the pen
            InPen();
            //Check to see if we are escapings
            JailbreakPlanning();
            break;

        case SheepState.Sheep_Escaping:
            //Running out of the pen
            Jailbreak();
            break;
        }
        //Check to see if they are outside camera range
        OnCamEdge();
        //Check to see if they collide with something
        //Update the position
        // UpdatePosition();
    }
Exemplo n.º 12
0
    // Start is called before the first frame update
    void Start()
    {
        _currentState    = SheepState.WANDERING;
        _wanderDirection = pickRandomDirection();

        _timeBeforeDirectionChange = UnityEngine.Random.Range(6.0f, 12.0f);

        _sheepDetectionSphere           = (SphereCollider)this.gameObject.AddComponent(typeof(SphereCollider));
        _sheepDetectionSphere.radius    = _sheepSightRadius;
        _sheepDetectionSphere.isTrigger = true;
    }
    public void GetSheared()
    {
        sheepState = SheepState.EnteringShearOMatic;
        var spiralFade = gameObject.AddComponent <SpiralFade>();

        spiralFade.endAction = () =>
        {
            SheepEnteredSheerOMatic();
            Destroy(gameObject);
        };
    }
Exemplo n.º 14
0
 public void CheckSheepState()
 {
     if (this.follower == null)
     {
         SS = SheepState.NOOWNER;
     }
     else
     {
         SS = SheepState.HAVEOWNER;
     }
 }
Exemplo n.º 15
0
    void Update()
    {
        switch (state)
        {
        case SheepState.Idle:
            // Check for possible flocking
            int        layerMask    = 1 << 8; // Sheep only
            Collider[] hitColliders = Physics.OverlapSphere(transform.position, VisionRadius, layerMask);

            if (hitColliders.Length > 1)        //
            {
                int   closest = -1;
                float minDist = -1;
                int   i       = 0;

                while (i < hitColliders.Length)
                {
                    float dist = (hitColliders[i].transform.position - transform.position).magnitude;
                    if (closest == -1 || dist < minDist)
                    {
                        if (dist > SheepHuddleDistance)
                        {
                            minDist = dist;
                            closest = i;
                        }
                    }
                    i++;
                }

                if (closest != -1)
                {
                    navAgent.destination = hitColliders[closest].transform.position;
                    state = SheepState.Flocking;
                }
            }
            else     // Meander
            {
                navAgent.destination = transform.position + Random.insideUnitSphere * SheepMeanderDistance;
                state = SheepState.Meandering;
            }
            break;

        case SheepState.Dispersing:
        case SheepState.Flocking:
        case SheepState.Meandering:
            if (navStopped())
            {
                state = SheepState.Idle;     // Done
            }
            break;
        }
    }
Exemplo n.º 16
0
    void OnTriggerExit(Collider other)
    {
        //Object needs to have a rigidbody for collisions.
        if (other.gameObject.CompareTag("Player"))
        {
            _currentState = SheepState.WANDERING;
        }

        if (other.gameObject.CompareTag("Crop"))
        {
            _currentState = SheepState.WANDERING;
        }
    }
Exemplo n.º 17
0
    private void Start()
    {
        state              = SheepState.idle;
        SightLength        = 2;
        Speed              = 0.3f;
        randomWalkRate     = 20;
        WalkDir            = new Vector2Int(1, 0);
        randomWalkTimeRate = 2.5f;

        anim   = GetComponent <Animator>();
        isDead = false;
        //findFood = true;
    }
Exemplo n.º 18
0
    public void HitByBark(Vector3 pos)
    {
        //The sheep was hit by a bark
        if (sheepState == SheepState.Sheep_Wander || sheepState == SheepState.Sheep_Avoid)
        {
            //Only do this if we're in the wander state or avoid state (to make sure you can't bark at sheep in the pen)
            lastBarkTime     = 0;
            currentDirection = (transform.position - pos).normalized;
            sheepState       = SheepState.Sheep_Barked;

            //Will this cause a problem with colliding other sheep?
        }
    }
Exemplo n.º 19
0
    public void DisperseFromPosition(Vector3 targetPos) // scalar has to be between 0 and 1
    {
        Vector3 disp = transform.position - targetPos;

        if (disp.magnitude < VisionRadius)
        {
            Vector3 dir      = disp.normalized;
            float   distance = (disp.magnitude / VisionRadius) * DisperseDistance;

            navAgent.destination = transform.position + (dir * distance);
        }

        state = SheepState.Dispersing;
    }
Exemplo n.º 20
0
    //add fox? that can herd them past those barriers
    void Jailbreak()
    {
        //pick a new random? direction
        if (jailbreakDirection != currentDirection)
        {
            jailbreakDirection = new Vector2(Random.Range(-1f, 0f), Random.Range(-1f, 1f)).normalized;
        }
        currentDirection = jailbreakDirection;
        //check to see if that will let them out of the pen

        if (!inPen)
        {
            sheepState = SheepState.Sheep_Wander;
        }
    }
Exemplo n.º 21
0
    void OnTriggerEnter(Collider other)
    {
        //Object needs to have a rigidbody for collisions.
        if (other.gameObject.CompareTag("Player"))
        {
            _currentState = SheepState.AFRAID;
        }

        if (other.gameObject.CompareTag("Crop") && _currentState != SheepState.CHASE_FOOD)
        {
            _currentState    = SheepState.CHASE_FOOD;
            _foodDirection   = (other.gameObject.transform.position - this.transform.position).normalized;
            _foodDirection.y = 0;
        }
    }
Exemplo n.º 22
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.tag == "Terrain")
        {
            _CurrentState = SheepState.Running;
        }

        if (collision.collider.tag == "Fence")
        {
            _PreviousState = _CurrentState;
            _CurrentState  = SheepState.Bounce;
        }

        if (collision.collider.tag == "Hazard")
        {
            _CurrentState = SheepState.Damaged;
        }
    }
Exemplo n.º 23
0
 void PlayerVisible()
 {
     if ((Vector2.Distance(transform.position, player.position) <= (scareDistance / 2)))
     {
         moveSpeed += 1f;
         if (Vector2.Distance(transform.position, player.position) <= scareDistance)
         {
             sheepState       = SheepState.Sheep_Avoid;
             playerToSheepDir = (transform.position - player.position).normalized;
             currentDirection = playerToSheepDir;
             currentMoveTimer = 0f;
         }
     }
     else
     {
         moveSpeed  = originalMoveSpeed;
         sheepState = SheepState.Sheep_Wander;
     }
 }
Exemplo n.º 24
0
    private void OnTriggerEnter(Collider other)
    {
        Wolf wolf = other.gameObject.GetComponent <Wolf>();

        if (wolf != null)
        {
            wolf.state = WolfState.attack;//当攻击动画播放完毕,Wolf恢复巡逻状态;
            isDead     = true;
            anim.SetTrigger("die");
            state = SheepState.dead;

            Invoke("DestroySelf", 3f);
            //Destroy(this.gameObject);
        }

        if (other.gameObject.GetComponent <DestPoint>() != null)
        {
            GameManager.GetInstance().MissionComplete();
        }
    }
Exemplo n.º 25
0
    public void SetState(SheepState newState)
    {
        //Debug.Log("Set new state: " + newState.ToString());

        _prevState = _state;
        _state     = newState;

        if (goToNewspaperNext && _prevState == SheepState.MoveToLean)
        {
            SetState(SheepState.Newspaper);
            goToNewspaperNext = false;
            return;
        }

        if (_prevState == SheepState.Newspaper)
        {
            newspaperDisplay.SetActive(false);
        }

        if (newState == SheepState.Idle)
        {
            if (_prevState == SheepState.MoveToLean || _prevState == SheepState.Newspaper)
            {
                idleTimer = UnityEngine.Random.Range(0f, settings.IdleTime);
            }
            else
            {
                idleTimer = settings.IdleTime;
            }

            SetSheepSprite(SheepSprite.Happy);
        }
        else if (newState == SheepState.Wandering)
        {
            float x = UnityEngine.Random.Range(this.transform.position.x - settings.WanderRange, this.transform.position.x + settings.WanderRange);
            float y = UnityEngine.Random.Range(localBounds.Top, localBounds.Bottom);

            if (x > localBounds.Right)
            {
                x = UnityEngine.Random.Range(this.transform.position.x - settings.WanderRange, this.transform.position.x - (settings.WanderRange * 2f));
            }
            else if (x < localBounds.Left)
            {
                x = UnityEngine.Random.Range(this.transform.position.x + settings.WanderRange, this.transform.position.x + (settings.WanderRange * 2f));
            }

            targetPos = new Vector3(x, y, 0f);
        }
        else if (newState == SheepState.MoveToLean)
        {
            // Target area.
            localBounds = CalculateLocalBounds(_lean);

            targetPos = CalculateTargetPosition();

            if (_prevState == SheepState.Newspaper)
            {
                SetSheepSprite(SheepSprite.Rage);
            }
            else if (_lean > prevLean)
            {
                SetSheepSprite(SheepSprite.Ecstatic);
            }
            else if (_lean < prevLean)
            {
                SetSheepSprite(SheepSprite.Sad);
            }
        }
        else if (newState == SheepState.Newspaper)
        {
            // Change sprite to newspaper reading!
            if (!goToNewspaperNext && _prevState == SheepState.MoveToLean)
            {
                goToNewspaperNext = true;
                _state            = SheepState.MoveToLean;
                return;
            }

            newspaperDisplay.SetActive(true);
        }
    }
 protected override void OnStateChanged(SheepState state)
 {
     //
 }
Exemplo n.º 27
0
    void MoveControl()
    {
        if (state == SheepState.dead)
        {
            return;
        }
        //New Struct

        /*if(!startRunToFood)
         * {
         *  Vector2Int foodPos = Vector2Int.zero;
         *  Vector2Int moveDir = Vector2Int.zero;
         *  var pawn = DetectFood(WalkDir, ref foodPos, ref moveDir);
         *  if (pawn != null)
         *  {
         *      Food f = pawn.transform.gameObject.GetComponent<Food>();
         *      if (f != null)
         *      {
         *          Debug.Log("Find it 1!");
         *
         *          //向食物移动;
         *          Speed = f.speed;
         *          //WalkTo(foodPos);
         *          WalkStep(moveDir);
         *          //Debug.Log("Food:" + foodPos.ToString());
         *          state = SheepState.chaseFood;
         *          findFood = true;
         *          startRunToFood = true;
         *      }
         *  }
         * }*/
        Vector2Int foodPos = Vector2Int.zero;
        Vector2Int moveDir = Vector2Int.zero;
        var        pawn    = DetectFood(WalkDir, ref foodPos, ref moveDir);

        if (pawn != null)
        {
            Food f = pawn.transform.gameObject.GetComponent <Food>();
            if (f != null)
            {
                Debug.Log("Find it 1!");

                //向食物移动;
                Speed = f.speed;
                //WalkTo(foodPos);
                WalkStep(moveDir);
                state    = SheepState.chaseFood;
                findFood = true;
            }
            else
            {
                findFood = false;
            }
        }
        else
        {
            if (!findFood)
            {
                t += Time.deltaTime;
                if (t > randomWalkTimeRate)
                {
                    t = 0;
                    //符合时间间隔;


                    //如果没有检测到食物,随机判定是否要行走;
                    int rate = Random.Range(0, 100);
                    if (rate <= randomWalkRate)//在随机行走范围内,则再进行一次随机来判定向哪个方向行走;
                    {
                        Vector2Int randomMoveDir = FindRandomDir();
                        WalkStep(randomMoveDir);
                        state = SheepState.walk;
                    }
                    else
                    {
                        //否则就呆在原地;
                        //Do Nothing
                        state = SheepState.idle;
                    }
                }
            }
        }


        //检测是否有食物;

        /*Vector2Int foodPos = Vector2Int.zero;
         * Vector2Int moveDir = Vector2Int.zero;
         * var pawn = DetectFood(WalkDir, ref foodPos,ref moveDir);
         * if(pawn!=null)
         * {
         *  Food f = pawn.transform.gameObject.GetComponent<Food>();
         *  if(f!=null)
         *  {
         *
         *      //向食物移动;
         *      Speed = f.speed;
         *      //WalkTo(foodPos);
         *      WalkStep(moveDir);
         *      state = SheepState.chaseFood;
         *  }
         * }
         * else
         * {
         *  t += Time.deltaTime;
         *  if(t> randomWalkTimeRate)
         *  {
         *      t = 0;
         *      //符合时间间隔;
         *
         *
         *      //如果没有检测到食物,随机判定是否要行走;
         *      int rate = Random.Range(0, 100);
         *      if (rate <= randomWalkRate)//在随机行走范围内,则再进行一次随机来判定向哪个方向行走;
         *      {
         *          Vector2Int randomMoveDir = FindRandomDir();
         *          WalkStep(randomMoveDir);
         *          state = SheepState.walk;
         *      }
         *      else
         *      {
         *          //否则就呆在原地;
         *          //Do Nothing
         *          state = SheepState.idle;
         *      }
         *  }
         * }*/
    }
Exemplo n.º 28
0
 protected abstract void OnStateChanged(SheepState state);
Exemplo n.º 29
0
 private void _BounceState()
 {
     _TurningAngle = 45;
     _CurrentState = _PreviousState;
 }
Exemplo n.º 30
0
 private void _DamagedState()
 {
     _Velocity     = Vector3.zero;
     _TurningAngle = 0;
     _CurrentState = SheepState.Running;
 }