public IEnumerator Walk()
    {
        FarmRoot      farmRoot  = FarmRoot.Instance;
        FarmField     farmField = farmRoot.Field;
        FarmDigimonAI ai        = base.GetComponent <FarmDigimonAI>();

        FarmDigimonAI.ActionParam param = ai.GetActionParam();
        float speed = 1.6f;

        if (param.pathGridIndexs != null && 0 < param.pathGridIndexs.Length)
        {
            int nowIndex   = param.pathGridIndexs.Length;
            int checkIndex = 0;
            while (checkIndex < nowIndex)
            {
                Vector3 digimonPos3D = base.transform.localPosition;
                digimonPos3D.y = 0f;
                int     gridIndex = param.pathGridIndexs[checkIndex];
                Vector3 gridPos3D = farmField.Grid.GetPositionGridCenter(gridIndex, false);
                gridPos3D.y = 0f;
                Vector3 rayDirection = gridPos3D - digimonPos3D;
                digimonPos3D.y = farmRoot.transform.localPosition.y + 0.1f;
                gridPos3D.y    = farmRoot.transform.localPosition.y + 0.1f;
                if (!Physics.Raycast(digimonPos3D, rayDirection, rayDirection.magnitude, this.MASK_LAYER))
                {
                    digimonPos3D.y = 0f;
                    gridPos3D.y    = 0f;
                    Vector3 digimonDirection      = Quaternion.AngleAxis(base.transform.localEulerAngles.y, Vector3.up) * Vector3.forward;
                    float   angle                 = Vector3.Angle(digimonDirection, rayDirection);
                    Vector3 digimonRightDirection = Quaternion.AngleAxis(90f, Vector3.up) * digimonDirection;
                    if (0f > Vector3.Dot(digimonRightDirection, rayDirection))
                    {
                        angle *= -1f;
                    }
                    this.enumerator = this.Turn(angle, speed);
                    Coroutine coroutine = base.StartCoroutine(this.enumerator);
                    if (40f <= Mathf.Abs(angle))
                    {
                        yield return(coroutine);
                    }
                    this.enumerator = this.Movement(digimonPos3D, gridPos3D, speed);
                    yield return(base.StartCoroutine(this.enumerator));

                    this.enumerator = null;
                    nowIndex        = checkIndex;
                    checkIndex      = 0;
                }
                else
                {
                    checkIndex += Mathf.Max(1, (nowIndex - checkIndex) / 2);
                }
            }
        }
        yield break;
    }
Example #2
0
    private IEnumerator WaitEndAction()
    {
        FarmDigimonAI.ActionParam param = this.farmDigimonAI.GetActionParam();
        switch (param.actionID)
        {
        case FarmDigimonAI.ActionID.MEAT_FARM:
        case FarmDigimonAI.ActionID.STROLL:
        case FarmDigimonAI.ActionID.STROLL_FAST:
        case FarmDigimonAI.ActionID.CONSTRUCTION:
            if (param.pathGridIndexs != null)
            {
                CharacterParams characterParams = this.digimon.GetComponent <CharacterParams>();
                characterParams.PlayAnimation(CharacterAnimationType.move, SkillType.Attack, 0, null, null);
                this.actionSubEnumerator = this.farmDigimonAction.Walk();
                yield return(base.StartCoroutine(this.actionSubEnumerator));

                this.actionSubEnumerator = null;
            }
            break;

        case FarmDigimonAI.ActionID.TOUCH_ACTION:
        {
            CharacterParams characterParams2 = this.digimon.GetComponent <CharacterParams>();
            characterParams2.PlayAnimation(CharacterAnimationType.move, SkillType.Attack, 0, null, null);
            this.actionSubEnumerator = this.farmDigimonAction.TouchAction();
            yield return(base.StartCoroutine(this.actionSubEnumerator));

            this.actionSubEnumerator = null;
            break;
        }

        default:
        {
            CharacterParams component = this.digimon.GetComponent <CharacterParams>();
            component.PlayAnimationSmooth(CharacterAnimationType.revival, SkillType.Attack, 0, null, null);
            break;
        }
        }
        CharacterParams component2 = this.digimon.GetComponent <CharacterParams>();

        component2.PlayAnimationSmooth(CharacterAnimationType.revival, SkillType.Attack, 0, null, null);
        yield return(new WaitForSeconds(5f));

        this.farmDigimonAI.ClearActionParam();
        this.actionState = FarmDigimon.ActionState.THINKING;
        yield return(null);

        yield break;
    }