void setDirection()
    {
        Vector3 scale = controller.transform.GetChild(0).localScale;

        if (direction == EDragonStateDirection.RIGHT)
        {
            controller.transform.GetChild(0).localScale = new Vector3(Mathf.Abs(scale.x), scale.y, scale.z);
        }
        else
        {
            controller.transform.GetChild(0).localScale = new Vector3(-1 * scale.x, scale.y, scale.z);
        }

        preDirection = direction;
    }
    public override void Execute(BabyDragonController obj)
    {
        Vector3 destPosition = obj.dragonParent.stateMove.listPosition[PlayConfig.BabyDragonIndexForListStart
                                                                       - PlayConfig.BabyDragonIndexForListDistance * obj.index];

        if (Vector3.Distance(obj.transform.position, destPosition) <= 0.01f)
        {
            obj.StateAction = EDragonStateAction.IDLE;
        }

        if (obj.transform.position != destPosition)
        {
            if (Time.timeScale != 0.0f)
            {
                if (obj.transform.position.x > destPosition.x)
                {
                    if (obj.StateDirection != EDragonStateDirection.LEFT)
                    {
                        obj.StateDirection = EDragonStateDirection.LEFT;
                    }
                }
                else
                {
                    if (obj.StateDirection != EDragonStateDirection.RIGHT)
                    {
                        obj.StateDirection = EDragonStateDirection.RIGHT;
                    }
                }
                obj.transform.position = Vector3.MoveTowards(obj.transform.position, destPosition, obj.attribute.Speed / 1000);
            }
        }

        if (preStateDirection != obj.StateDirection)
        {
            preStateDirection = obj.StateDirection;

            if (obj.StateDirection == EDragonStateDirection.LEFT)
            {
                Vector3 scale = obj.transform.GetChild(0).localScale;
                obj.transform.GetChild(0).localScale = new Vector3(-1 * scale.x, scale.y, scale.z);
            }
            else
            {
                Vector3 scale = obj.transform.GetChild(0).localScale;
                obj.transform.GetChild(0).localScale = new Vector3(Mathf.Abs(scale.x), scale.y, scale.z);
            }
        }
    }
Exemple #3
0
    void Awake()
    {
        stateAttack = new BabyDragonStateAttack();
        stateDie    = new BabyDragonStateDie();
        stateIdle   = new BabyDragonStateIdle();
        stateMove   = new BabyDragonStateMove();

        FSM = new FiniteStateMachine <BabyDragonController>();

        babyAnimation = this.transform.GetChild(0).GetComponent <BabyDragonAnimation>();
        babyAttack    = this.GetComponentInChildren <BabyDragonAttack>();

        StateAction    = EDragonStateAction.IDLE;
        StateDirection = EDragonStateDirection.LEFT;

        attribute.HP.Current = attribute.HP.Max;
    }
    public override void Enter(EnemyController obj)
    {
        controller = obj;

        if (target.transform.position.x >= controller.transform.position.x)
        {
            controller.stateAttack.direction = EDragonStateDirection.RIGHT;
        }
        else
        {
            controller.stateAttack.direction = EDragonStateDirection.LEFT;
        }

        preDirection      = direction;
        preTargetPosition = target.transform.position;
        setDirection();
    }
    void Awake()
    {
        stateAttack = new BabyDragonStateAttack();
        stateDie = new BabyDragonStateDie();
        stateIdle = new BabyDragonStateIdle();
        stateMove = new BabyDragonStateMove();

        FSM = new FiniteStateMachine<BabyDragonController>();

        babyAnimation = this.transform.GetChild(0).GetComponent<BabyDragonAnimation>();
        babyAttack = this.GetComponentInChildren<BabyDragonAttack>();

        StateAction = EDragonStateAction.IDLE;
        StateDirection = EDragonStateDirection.LEFT;

        attribute.HP.Current = attribute.HP.Max;
    }
Exemple #6
0
    public override void Enter(DragonController obj)
    {
        //Debug.Log(obj.StateDirection);
        if (obj.StateDirection == EDragonStateDirection.LEFT)
        {
            Vector3 scale = obj.transform.GetChild(0).localScale;
            obj.transform.GetChild(0).localScale = new Vector3(-1 * Mathf.Abs(scale.x), scale.y, scale.z);
        }
        else
        {
            Vector3 scale = obj.transform.GetChild(0).localScale;
            obj.transform.GetChild(0).localScale = new Vector3(Mathf.Abs(scale.x), scale.y, scale.z);
        }

        preStateDirection = obj.StateDirection;
        Movement          = EDragonMovement.MOVE_TOUCH;
    }
Exemple #7
0
    public override void Execute(DragonController obj)
    {
        if (target == null)
        {
            controller.dragonAttack.chooseEnemyToAttack();
            return;
        }
        else
        {
            EnemyController enemy = target.GetComponent <EnemyController>();
            if (enemy.attribute.HP.Current <= 0)
            {
                controller.dragonAttack.listEnemy.Remove(target);
                target = null;
                controller.dragonAttack.chooseEnemyToAttack();

                enemy.die();
                return;
            }
        }

        if (target.transform.position.x >= controller.transform.position.x && direction == EDragonStateDirection.LEFT)
        {
            direction = EDragonStateDirection.RIGHT;

            if (preDirection != direction)
            {
                setDirection();
            }
        }
        else if (target.transform.position.x < controller.transform.position.x && direction == EDragonStateDirection.RIGHT)
        {
            direction = EDragonStateDirection.LEFT;

            if (preDirection != direction)
            {
                setDirection();
            }
        }
    }
Exemple #8
0
    public override void Enter(EnemyController obj)
    {
        Transform[] temps = PathGroup.GetComponentsInChildren <Transform>();
        Paths = new Transform[temps.Length - 1];
        int count = 0;

        for (int i = 0; i < temps.Length; i++)
        {
            if (temps[i] != PathGroup)
            {
                Paths[count] = temps[i];
                count++;
            }
        }

        Vector3 scale = obj.transform.GetChild(0).localScale;

        obj.transform.GetChild(0).localScale = new Vector3(Mathf.Abs(scale.x), scale.y, scale.z);

        State     = EEnemyMovement.MOVE_ON_PATHS;
        Direction = EDragonStateDirection.LEFT;
    }
    public override void Execute(EnemyController obj)
    {
        if (!obj.isEnable)
        {
            return;
        }

        if (target == null)
        {
            controller.stateMove.State = EEnemyMovement.MOVE_ON_PATHS;
            controller.StateAction     = EEnemyStateAction.MOVE;
            return;
        }
        else
        {
            if (target.GetComponent <DragonController>() != null)
            {
                DragonController dragonController = target.GetComponent <DragonController>();
                if (dragonController.attribute.HP.Current <= 0)
                {
                    dragonController.StateAction  = EDragonStateAction.DIE;
                    dragonController.StateOffense = EDragonStateOffense.NONE;
                    controller.StateAction        = EEnemyStateAction.MOVE;
                    target = null;
                    return;
                }
            }
            else
            {
                BabyDragonController babyController = target.GetComponent <BabyDragonController>();
                if (babyController.attribute.HP.Current <= 0)
                {
                    babyController.StateAction = EDragonStateAction.DIE;

                    controller.enemyAttack.listDragon.Remove(target);
                    target = null;
                    controller.enemyAttack.chooseDragonToAttack();
                    return;
                }
            }
        }

        if (target.transform.position.x >= controller.transform.position.x && direction == EDragonStateDirection.LEFT)
        {
            direction = EDragonStateDirection.RIGHT;

            if (preDirection != direction)
            {
                setDirection();
            }
        }
        else if (target.transform.position.x < controller.transform.position.x && direction == EDragonStateDirection.RIGHT)
        {
            direction = EDragonStateDirection.LEFT;

            if (preDirection != direction)
            {
                setDirection();
            }
        }

        if (preTargetPosition != target.transform.position)
        {
            if (target.transform.position.x < controller.transform.position.x)
            {
                controller.stateMove.Direction = EDragonStateDirection.RIGHT;
            }
            else
            {
                controller.stateMove.Direction = EDragonStateDirection.LEFT;
            }

            controller.stateMove.State = EEnemyMovement.MOVE_TO_DRAGON;
            controller.StateAction     = EEnemyStateAction.MOVE;
        }
    }
Exemple #10
0
    public override void Execute(DragonController obj)
    {
        if (Movement == EDragonMovement.MOVE_TOUCH)
        {
            if (preFrag != destFrag)
            {
                preFrag = destFrag;
                PlayTouchManager.Instance.checkFrag(destFrag, false);
            }

            if (Vector3.Distance(obj.transform.position, destPosition) <= PlayConfig.DistanceBulletChase)
            {
                obj.StateAction = EDragonStateAction.IDLE;
                PlayTouchManager.Instance.checkFrag(destFrag, true);
            }
        }
        else if (Movement == EDragonMovement.MOVE_TO_ENEMY)
        {
            GameObject  enemy       = obj.stateAttack.target;
            BoxCollider boxCollider = obj.stateAttack.target.GetComponentInChildren <BoxCollider>();
            Vector3     vec3        = new Vector3(boxCollider.size.x / 2, 0, 0);
            destPosition = new Vector3(enemy.transform.position.x + (attackDirection == EDragonStateDirection.LEFT ? -vec3.x : vec3.x) * PlayManager.Instance.tempInit.uiRoot.transform.localScale.x,
                                       enemy.transform.position.y - vec3.y * PlayManager.Instance.tempInit.uiRoot.transform.localScale.y,
                                       enemy.transform.position.z);

            if (Vector3.Distance(obj.transform.position, destPosition) <= 0.1f)
            {
                obj.StateAction = EDragonStateAction.ATTACK;
            }
        }
        else if (Movement == EDragonMovement.MOVE_TO_HOUSE)
        {
            if (preFrag != destFrag)
            {
                preFrag = destFrag;
                PlayTouchManager.Instance.checkFrag(destFrag, false);
            }

            if (Vector3.Distance(obj.transform.position, destPosition) <= PlayConfig.DistanceBulletChase)
            {
                obj.StateAction = EDragonStateAction.IDLE;
                PlayDragonManager.Instance.copulateIn();
            }
        }

        if (obj.transform.position != destPosition)
        {
            if (Time.timeScale != 0.0f)
            {
                obj.transform.position = Vector3.MoveTowards(obj.transform.position, destPosition, obj.attribute.Speed / 1000);

                if (PlayDragonManager.Instance.countBaby > 0)
                {
                    listPosition.Add(obj.transform.position);

                    if (countList >= 100)
                    {
                        listPosition.RemoveAt(0);
                    }
                    else
                    {
                        countList++;
                    }
                }
            }
        }

        if (preStateDirection != obj.StateDirection)
        {
            preStateDirection = obj.StateDirection;

            if (obj.StateDirection == EDragonStateDirection.LEFT)
            {
                Vector3 scale = obj.transform.GetChild(0).localScale;
                obj.transform.GetChild(0).localScale = new Vector3(-1 * Mathf.Abs(scale.x), scale.y, scale.z);
            }
            else
            {
                Vector3 scale = obj.transform.GetChild(0).localScale;
                obj.transform.GetChild(0).localScale = new Vector3(Mathf.Abs(scale.x), scale.y, scale.z);
            }
        }
    }
 public override void Enter(BabyDragonController obj)
 {
     preStateDirection = obj.StateDirection;
 }