Esempio n. 1
0
    public override State Update()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        float distance = Vector3.Distance(myBody.transform.position, fireSlimeBoss.currentTarget.transform.position);

        //如果有目标在视野内,则移动向目标,直到可以攻击到目标
        if (distance < attackRange)
        {
            Debug.Log(distance + " 1 " + attackRange);
            myBody.GetComponent <Rigidbody2D>().velocity = Vector3.zero;
            return(State.SUCESSED);
        }

        BossRoom_FireSlimeScene room = (BossRoom_FireSlimeScene)myBody.GetComponentInParent(typeof(BossRoom_FireSlimeScene));
        float dx = myBody.transform.position.x;
        float dy = myBody.transform.position.y;

        if (dx >= room.transform.position.x + room.dx || dx <= room.transform.position.x - room.dx)
        {
            myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(0, myBody.GetComponent <Rigidbody2D>().velocity.y);
        }
        if (dy >= room.transform.position.y + room.dy || dy <= room.transform.position.y - room.dy)
        {
            myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(myBody.GetComponent <Rigidbody2D>().velocity.x, 0);
        }

        Vector3 dir = (fireSlimeBoss.currentTarget.transform.position - myBody.transform.position).normalized;

        myBody.GetComponent <Rigidbody2D>().velocity = dir * speed * Time.deltaTime;
        Debug.Log(dir + " " + myBody.GetComponent <Rigidbody2D>().velocity + " " + speed);
        return(State.RUNNING);
    }
Esempio n. 2
0
    public override State Update()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        if (currentPreperaTime < prepareTime)
        {
            currentPreperaTime += Time.deltaTime;
        }
        else
        {
            if (!isFire)
            {
                GameObject iFireBomb = Object.Instantiate(fireBomb, myBody.transform.position, Quaternion.identity);
                Vector3    dir       = (fireSlimeBoss.currentTarget.transform.position - myBody.transform.position).normalized;
                Debug.DrawLine(myBody.transform.position, fireSlimeBoss.currentTarget.transform.position);
                iFireBomb.GetComponent <Rigidbody2D>().velocity = dir * fireSpeed * Time.deltaTime;
                isFire = true;
            }
            else
            {
                if (currentRecoverTime < recoverTime)
                {
                    currentRecoverTime += Time.deltaTime;
                }
                else
                {
                    return(State.SUCESSED);
                }
            }
        }
        return(State.RUNNING);
    }
Esempio n. 3
0
    public override void Enter()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        if (childrenStates.Count == 0)
        {
            Skill1State_FireSlimeBoss       skill1State       = new Skill1State_FireSlimeBoss();
            Skill2State_FireSlimeBoss       skill2State       = new Skill2State_FireSlimeBoss();
            Skill3State_FireSlimeBoss       skill3State       = new Skill3State_FireSlimeBoss();
            NormalAttackState_FireSlimeBoss normalAttackState = new NormalAttackState_FireSlimeBoss();

            skill1State.SetCharacterAI(GetAI());
            skill2State.SetCharacterAI(GetAI());
            skill3State.SetCharacterAI(GetAI());
            normalAttackState.SetCharacterAI(GetAI());

            AddChild(skill3State);
            AddChild(skill2State);
            AddChild(skill1State);
            AddChild(normalAttackState);
        }
        Debug.Log("进入攻击状态");
        base.Enter();
    }
Esempio n. 4
0
    public override State Update()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        if (currentPrepareTime < prepareTime)
        {
            currentPrepareTime += Time.deltaTime;
            currentState        = State.RUNNING;
        }
        else
        {
            if (!isFire)
            {
                Fire();
                currentState = State.RUNNING;
                isFire       = true;
            }
            else
            {
                if (currentRecoverTime < recoverTime)
                {
                    currentRecoverTime += Time.deltaTime;
                    currentState        = State.RUNNING;
                }
                else
                {
                    return(State.SUCESSED);
                }
            }
        }
        return(currentState);
    }
Esempio n. 5
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        attackRange = fireSlimeBoss.getAttr().getAttackRange();

        Debug.Log("判断距离是否足够");
    }
Esempio n. 6
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        fusedLaserBall     = fireSlimeBoss.fusedLaserBall;
        currentRecoverTime = 0;
        currentPrepareTime = 0;
        isFire             = false;
    }
Esempio n. 7
0
    private void Fire()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        GameObject iFireBomb = GameObject.Instantiate(FireBomb, myBody.transform.position, Quaternion.identity);
        Vector3    dir       = (fireSlimeBoss.currentTarget.transform.position - myBody.transform.position).normalized;

        iFireBomb.GetComponent <Rigidbody2D>().velocity = dir * FireBombSpeed * Time.deltaTime;
    }
Esempio n. 8
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        FireBomb           = fireSlimeBoss.GetFireBall();
        currentPrepareTime = 0;
        currentRecoverTime = 0;
        isFire             = false;
        Debug.Log("进入skill1");
    }
Esempio n. 9
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        fireBomb           = fireSlimeBoss.GetFireBall();
        isFire             = false;
        currentPreperaTime = 0;
        currentRecoverTime = 0;
        Debug.Log("普攻");
    }
Esempio n. 10
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        theEjectedMagma    = fireSlimeBoss.GetTheEjectedMagma();
        target             = fireSlimeBoss.target;
        currentLastTime    = 0;
        currentPrepareTime = 0;
        count = 0;
        Debug.Log("进入skill2");
    }
Esempio n. 11
0
    public override State Update()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();
        float           distance        = Vector3.Distance(myBody.transform.position, fireSlimeBoss.currentTarget.transform.position);

        Debug.Log(distance + " " + attackRange);
        if (distance < attackRange)
        {
            Debug.Log("距离足够");
            return(State.SUCESSED);
        }
        Debug.Log("距离不够");
        return(State.FAILED);
    }
Esempio n. 12
0
    private void CreateFusedLaserBall()
    {
        float      dx = 0;
        float      dy = 0;
        GameObject iTarget;
        Vector3    pos = new Vector3();

        dx = Random.Range(-range, range);
        dy = Random.Range(-Mathf.Pow(range * range - dx * dx, 0.5f), Mathf.Pow(range * range - dx * dx, 0.5f));
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        pos = myBody.transform.position + new Vector3(dx, dy);
        while (Physics2D.OverlapCircle(pos, 1, LayerMask.GetMask("FusedLaserBall")) != null)
        {
            dx  = Random.Range(-range, range);
            dy  = Random.Range(-Mathf.Pow(range * range - dx * dx, 0.5f), Mathf.Pow(range * range - dx * dx, 0.5f));
            pos = myBody.transform.position + new Vector3(dx, dy);
        }
        GameObject iFuserLaserBall = Object.Instantiate(fusedLaserBall, pos, Quaternion.identity);
    }
Esempio n. 13
0
    public override State Update()
    {
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
        GameObject      myBody          = fireSlimeBoss.GetGameObject();

        if (fireSlimeBoss.currentTarget != null)
        {
            Debug.Log("存在敌人");
            return(State.SUCESSED);
        }

        fireSlimeBoss.targets = Physics2D.OverlapCircleAll(myBody.transform.position, eyeViewDistance, LayerMask.GetMask("Player"));
        Collider2D[] targets = fireSlimeBoss.targets;

        if (targets != null && targets.Length > 0)
        {
            fireSlimeBoss.currentTarget = targets[0];
            return(State.SUCESSED);
        }
        return(State.FAILED);
    }
Esempio n. 14
0
    private void JetSlush()
    {
        float dx = 0;
        float dy = 0;

        Vector3 pos = new Vector3();

        if (!canFire)
        {
            dx = Random.Range(-range, range);
            dy = Random.Range(-Mathf.Pow(range * range - dx * dx, 0.5f), Mathf.Pow(range * range - dx * dx, 0.5f));
            FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
            FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();
            GameObject      myBody          = fireSlimeBoss.GetGameObject();
            pos = myBody.transform.position + new Vector3(dx, dy);
            while (Physics2D.OverlapCircle(pos, 1, LayerMask.GetMask("MoltenLava")) != null || Physics2D.OverlapCircle(pos, 1, LayerMask.GetMask("Magma")) != null)
            {
                dx  = Random.Range(-range, range);
                dy  = Random.Range(-Mathf.Pow(range * range - dx * dx, 0.5f), Mathf.Pow(range * range - dx * dx, 0.5f));
                pos = myBody.transform.position + new Vector3(dx, dy);
            }
            canFire = true;
        }
        else
        {
            if (count < 1)
            {
                count  += Time.deltaTime;
                iTarget = Object.Instantiate(target, new Vector3(dx, dy), Quaternion.identity);
            }
            else
            {
                Object.Destroy(iTarget);
                GameObject iLava = Object.Instantiate(theEjectedMagma, pos, Quaternion.identity);
                count   = 0;
                canFire = false;
            }
        }
    }
Esempio n. 15
0
    public override void Enter()
    {
        base.Enter();
        FireSlimeBossAI fireSlimeBossAI = (FireSlimeBossAI)GetAI();
        FireSlimeBoss   fireSlimeBoss   = (FireSlimeBoss)fireSlimeBossAI.getCharacter();

        if (childrenStates.Count == 0)
        {
            ConditionCoolTime_FireSlimeBoss  conditionCoolTime  = new ConditionCoolTime_FireSlimeBoss(0);
            ConditionHaveEnemy_FireSlimeBoss conditionHaveEnemy = new ConditionHaveEnemy_FireSlimeBoss();
            RepeatDecoratorNode          repeatDecoratorNode    = new RepeatDecoratorNode(5);
            LaunchFireBomb_FireSlimeBoss launchFireBomb         = new LaunchFireBomb_FireSlimeBoss();
            conditionCoolTime.SetCharacterAI(GetAI());
            conditionHaveEnemy.SetCharacterAI(GetAI());
            repeatDecoratorNode.SetCharacterAI(GetAI());
            launchFireBomb.SetCharacterAI(GetAI());

            repeatDecoratorNode.AddChild(launchFireBomb);
            AddChild(conditionCoolTime);
            AddChild(conditionHaveEnemy);
            AddChild(repeatDecoratorNode);
        }
        Debug.Log("判断skill1");
    }