Example #1
0
    // update
    public virtual void MoveTowards(RoleBase tar)
    {
        Vector3 vec = tar.GetFootPos() - this.GetFootPos();

        // calculation the deviation
        if (Mathf.Abs(tar.GetFootPos().y - this.GetFootPos().y) <= tar.m_BeAtkWidth)
        {
            if (tar.GetFootPos().y - this.GetFootPos().y > 0)
            {
                vec = new Vector3(vec.x,
                                  vec.y - (Mathf.Abs(tar.GetFootPos().y - this.GetFootPos().y)), 0);
            }
            else
            {
                vec = new Vector3(vec.x,
                                  vec.y + (Mathf.Abs(tar.GetFootPos().y - this.GetFootPos().y)), 0);
            }
        }
        else
        {
            if (tar.GetFootPos().y - this.GetFootPos().y > 0)
            {
                vec = new Vector3(vec.x, 0, vec.y - tar.m_BeAtkWidth);
            }
            else
            {
                vec = new Vector3(vec.x, 0, vec.y + tar.m_BeAtkWidth);
            }
        }

        this.Move(vec);
    }
Example #2
0
 protected virtual void UpdateAtkTarget()
 {
     if (m_CurAtkTar != null)
     {
         // m_CurVec_AtkTar = (m_CurAtkTar.GetFootPos() -
         //     this.GetFootPos()).normalized;
         this.SetCurVec_Atk(m_CurAtkTar.GetFootPos() -
                            this.GetFootPos());
     }
     else
     {
         // m_CurVec_AtkTar = Vector2.zero;
         this.SetCurVec_Atk(Vector2.zero);
     }
 }
Example #3
0
    protected virtual bool CheckAttack(RoleBase tar)
    {
        if (tar == null)
        {
            return(false);
        }

        if (tar.m_CurStatus == RoleStatus.Die)
        {
            return(false);
        }

        float dis2Castle = Vector3.Distance(this.GetFootPos(),
                                            tar.GetFootPos());


        return(dis2Castle <= m_AtkRange);
    }
Example #4
0
    public override List <RoleBase> GetCurAtkTargetList()
    {
        List <RoleBase> enemies = new List <RoleBase>();

        foreach (RoleBase one in EnemyManager.instance.m_Enemies)
        {
            if (Vector3.Distance(this.GetFootPos(), one.GetFootPos()) <
                m_CurWeapon.m_AlertRange &&
                one.m_CurStatus != RoleStatus.Die)
            {
                enemies.Add(one);
            }
        }

        // planesID
        int mineHeroPlanesID = Global.instance.m_Hero_01.m_CurPlanesID;

        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            RoleBase oneRole = enemies[i];
            if (oneRole.m_CurPlanesID != Constants.PlanesID_Public &&
                m_CurPlanesID != oneRole.m_CurPlanesID)
            {
                enemies.RemoveAt(i);
            }
            else if (m_CurPlanesID == mineHeroPlanesID && m_CurPlanesID != Constants.PlanesID_Public)
            {
                m_AniMng.SetAlpha(0.3f);
            }
            else
            {
                // m_AniMng.SetAlpha(0f);
            }
        }


        // 2ddl
        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            RoleBase oneRole = enemies[i];
            Vector2  dir     = (oneRole.GetFootPos() -
                                this.GetFootPos()).normalized;
            LayerMask tLayer = m_TarLayer & (~(
                                                 1 << LayerMask.NameToLayer("Plane")
                                                 ));
            // check raycast
            RaycastHit2D hit = Physics2D.Raycast(
                this.GetMidPos(), dir,
                m_CurWeapon.m_AlertRange, tLayer);
            Debug.DrawLine(this.GetMidPos(), this.GetMidPos() + (Vector3)dir * 10, Color.red);
            if (hit.collider != null)
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Scene"))
                {
                    enemies.RemoveAt(i);
                }
            }
            //   m_TarLayer.dw
        }

        return(enemies);
    }
Example #5
0
    void FixedUpdate()
    {
        m_Time += Time.deltaTime;

        switch (m_PlayType)
        {
        case EffectPlayType.Bezier:
        {
            if (Vector3.Distance(m_TarPos, transform.position)
                < m_MoveVec * Time.deltaTime)
            {
                if (!IsInvoking("DestroySelf"))
                {
                    Invoke("DestroySelf", m_DestroyDelay);

                    // enable damage
                    Damage dmg = gameObject.GetComponent <Damage>();
                    if (dmg != null)
                    {
                        dmg.enabled = true;
                    }
                    // play the particle of explosion
                    if (m_BezierEndParticle != null)
                    {
                        ParticleManager.instance.CreateParticle(
                            m_BezierEndParticle,
                            m_TarPos, Vector3.zero
                            );
                        m_ParticleSystem.Stop();
                        AudioManager.instance.Play("Explosion_FireBall_01");
                    }
                }
            }

            // bezier
            Bezier myBezier = new Bezier(m_StartPos,
                                         new Vector3(0f, m_BezierCtrlHight, 0f),
                                         new Vector3(0f, m_BezierCtrlHight, 0f), m_TarPos);
            float allTime = Vector3.Distance(m_StartPos, m_TarPos) / m_MoveVec;
            float temp    = Mathf.Clamp(m_Time / allTime, 0f, 1f);

            // pow 2
            // temp = m_Time / (Mathf.Pow(allTime, 2));
            // temp = Mathf.Pow(temp, 3);

            m_CurPos           = myBezier.GetPointAtTime(temp);
            transform.position = m_CurPos;

            // rotate
            // transform.Rotate(new Vector3(0, 0, 1) * Time.deltaTime);
        }
        break;

        case EffectPlayType.Boomerang:
        {
            if (!IsInvoking("DestroySelf"))
            {
                Invoke("DestroySelf", m_DestroyDelay);

                // enable damage
                Damage dmg = gameObject.GetComponent <Damage>();
                if (dmg != null)
                {
                    dmg.enabled = true;
                }
            }
            if (Vector3.Distance(m_TarPos, transform.position)
                < m_MoveVec * Time.deltaTime)
            {
                temp_BoomerangTurnTarget = true;
            }
            if (Vector3.Distance(m_StartPos, transform.position)
                < Vector3.Distance(m_TarPos, transform.position) * 1.3 && temp_BoomerangTurnTarget == true)
            {
                if (m_Creater != null)
                {
                    m_EndPos = m_Creater.GetFootPos();
                }
                else
                {
                    m_EndPos = m_StartPos;
                }
                temp_Move = false;
            }
            if (Vector3.Distance(m_EndPos, transform.position)
                < m_MoveVec * Time.deltaTime * 2 && temp_BoomerangTurnTarget == true)
            {
                Destroy(gameObject);
            }
            if (temp_Move)
            {
                BoomerangBezier(m_TarPos, m_EndPos);
            }
            if (!temp_Move)
            {
                ComeBakeMoveBack();
            }
        }
        break;

        case EffectPlayType.Hold:
        case EffectPlayType.Charge:
        {
            // keep with creater
            if (m_Creater.m_CurStatus == RoleStatus.Die)
            {
                Destroy(gameObject);
                return;
            }

            transform.position = m_Creater.GetMidPos();
        }
        break;

        default:
            break;
        }
    }
Example #6
0
    public override List <RoleBase> GetCurAtkTargetList()// we can use parent scripts method
    {
        List <RoleBase> enemies = new List <RoleBase>();

        foreach (RoleBase one in Global.instance.m_Hero_All)
        {
            if (one == null)
            {
                continue;
            }
            if (Vector3.Distance(this.GetFootPos(), one.GetFootPos()) <
                m_CurWeapon.m_AlertRange &&
                one.m_CurStatus != RoleStatus.Die)
            {
                enemies.Add(one);
            }
        }

        // sort by priority and distance
        enemies.Sort(
            delegate(RoleBase x, RoleBase y)
        {
            if (Vector3.Distance(this.GetFootPos(), x.GetFootPos()) <
                Vector3.Distance(this.GetFootPos(), y.GetFootPos()))
            {
                return(-1);
            }
            else if (Vector3.Distance(this.GetFootPos(), x.GetFootPos()) >
                     Vector3.Distance(this.GetFootPos(), y.GetFootPos()))
            {
                return(1);
            }

            return(0);
        });

        // planesID
        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            RoleBase oneRole = enemies[i];
            if (oneRole.m_CurPlanesID != Constants.PlanesID_Public &&
                m_CurPlanesID != oneRole.m_CurPlanesID)
            {
                enemies.RemoveAt(i);
            }
        }


        // 2ddl
        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            RoleBase oneRole = enemies[i];
            Vector2  dir     = (oneRole.GetFootPos() -
                                this.GetFootPos()).normalized;
            LayerMask tLayer = m_TarLayer & (~(
                                                 1 << LayerMask.NameToLayer("Plane")
                                                 ));
            // check raycast
            RaycastHit2D hit = Physics2D.Raycast(
                this.GetAtkStartPos(), dir,
                m_CurWeapon.m_AlertRange, tLayer);
            if (hit.collider != null)
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Scene"))
                {
                    enemies.RemoveAt(i);
                }
            }
        }
        return(enemies);
    }