public void ChangeMoveStateTo(AIMoveState aiMoveStateToChange)
    {
        currentMoveState = aiMoveStateToChange;
        switch (currentMoveState)
        {
        case AIMoveState.Idle:
            isChasing = isEvading = false;
            break;

        case AIMoveState.Chase:
            isChasing = true;
            isEvading = false;
            break;

        case AIMoveState.Flee:
            isChasing = false;
            isEvading = true;
            break;

        default:
            break;
        }
        UpdateAnimatorValues <bool>("isChasing", isChasing);
        UpdateAnimatorValues <bool>("isEvading", isEvading);
        return;
    }
Example #2
0
    IEnumerator CheckSelfCondition()
    {
        if (this.targetPlayer != null)
        {
            int engageChance = UnityEngine.Random.Range(0, 100);

            if (player.GetHP() > engageChance)
            {
                this.state = AIMoveState.ENGAGE;
            }
            else
            {
                this.state = AIMoveState.AVOID;
            }
            yield return(new WaitForSeconds(0.2F));
        }
        else if (this.targetObject != null && this.targetPlayer == null)
        {
            TakeFuel fuel_condition = targetObject.GetComponent <TakeFuel>();
            if (fuel_condition != null && fuel_condition.IsFuelReady())
            {
                this.state = AIMoveState.CATCH;
                yield return(new WaitForSeconds(0.2F));
            }
        }

        yield break;
    }
Example #3
0
 public static AIMoveState Instance()
 {
     if (instance == null)
     {
         instance = new AIMoveState();
     }
     return(instance);
 }
Example #4
0
 void Start()
 {
     this.player         = this.transform.parent.transform.parent.gameObject.GetComponent <Player>();
     this.direction      = new Vector2(0.0F, 0.0F);
     this.offset         = new Vector2(0.0F, 0.0F);
     this.targetPosition = (Vector2)this.transform.position;
     state = AIMoveState.IDLE;
 }
Example #5
0
    void SetMovementState()
    {
        int randomNumber = Random.Range(0, 1000);

        switch (currentMoveState)
        {
        case AIMoveState.moreRight:
            if (randomNumber <= 30)
            {
                currentMoveState = AIMoveState.idel;
            }
            else
            {
                transform.position = new Vector2(transform.position.x + moveSpeed * Time.deltaTime, transform.position.y);
                if (transform.rotation.eulerAngles.y != 0)
                {
                    transform.localEulerAngles = new Vector3(0, 0, 0);
                }
            }
            break;

        case AIMoveState.moveLeft:
            if (randomNumber <= 30)
            {
                currentMoveState = AIMoveState.idel;
            }
            else
            {
                transform.position = new Vector2(transform.position.x - moveSpeed * Time.deltaTime, transform.position.y);
                if (transform.rotation.eulerAngles.y != 180)
                {
                    transform.localEulerAngles = new Vector3(0, 180, 0);
                }
            }
            break;

        case AIMoveState.idel:
            if (randomNumber <= 100)
            {
                currentMoveState = AIMoveState.moveLeft;
            }
            if (randomNumber >= 900)
            {
                currentMoveState = AIMoveState.moreRight;
            }
            break;

        case AIMoveState.disabled:
        default:
            break;
        }
    }
Example #6
0
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            this.targetPlayer = null;
        }
        else if (other.CompareTag("Fuel Bottom") || other.CompareTag("Fuel Top"))
        {
            this.targetObject = null;
        }

        this.state = AIMoveState.IDLE;
        StopCoroutine(CheckSelfCondition());
        StopCoroutine(ExecuteScript());
    }
Example #7
0
        public override void onMessage(AIMoveController obj, StateMsg <AIMoveController> msg)
        {
            AIMsg type = (AIMsg)msg.type;

            switch (type)
            {
            case AIMsg.findPathOk:
                obj.getSM().changeState(AIMoveState.Instance());
                break;

            case AIMsg.catchByTrap:
                obj.getSM().changeState(AICatchByTrapState.Instance());
                break;

            case AIMsg.catchPlayer:
                obj.getSM().changeState(AICatchPlayerState.Instance());
                break;
            }
        }
Example #8
0
    IEnumerator ExecuteScript()
    {
        if (targetPlayer != null)
        {
            if (this.state == AIMoveState.ENGAGE)
            {
                if (IsStuck())
                {
                    RandomMove();
                }
                else
                {
                    this.targetPosition = (Vector2)this.targetPlayer.transform.position;
                    this.offset         = this.targetPosition - (Vector2)this.transform.position;
                }
            }
            else if (this.state == AIMoveState.AVOID)
            {
                this.targetPosition = (Vector2)this.targetPlayer.transform.position;
                this.offset         = (Vector2)this.transform.position - this.targetPosition;
            }

            this.lastPosition = new Vector2(player.GetPositionX(), player.GetPositionY());
            this.direction    = Vector2.ClampMagnitude(offset, 0.15f);
            float changeDirectionDelay = UnityEngine.Random.Range(changeDirectionDelayRange.x, changeDirectionDelayRange.y);
            yield return(new WaitForSeconds(changeDirectionDelay));
        }
        else if (this.targetObject != null && this.targetPlayer == null && this.state == AIMoveState.CATCH)
        {
            this.targetPosition = (Vector2)this.targetObject.transform.position;
            this.offset         = this.targetPosition - (Vector2)this.transform.position;
            this.direction      = Vector2.ClampMagnitude(offset, 0.15f);
            yield return(new WaitForSeconds(0.5f));
        }

        if (targetPlayer == null && targetObject == null)
        {
            this.state = AIMoveState.IDLE;
            StopCoroutine(CheckSelfCondition());
        }

        yield break;
    }