Example #1
0
        public static bool GetAtkTarget(CCreature m_creature, BtDatabase m_dataBase, int lookDis)
        {
            // 仇恨值高的优先作为目标
            int       hTargetUid = m_creature.m_ai.GetHightHatred();
            CCreature hTargetCC  = CCreatureMgr.Get(hTargetUid);

            if (hTargetUid != -1 &&
                hTargetCC != null &&
                !hTargetCC.IsDie())   // 有仇恨对象,并且没死
            {
                m_dataBase.SetData <int>((int)eAIParam.INT_TARGET_UID, hTargetUid);
            }

            // 如果有目标,判断是否距离足够远,远了就清空目标,继续找附近的
            int       targetUid = m_dataBase.GetData <int>((int)eAIParam.INT_TARGET_UID);
            CCreature targetCC  = CCreatureMgr.Get(targetUid);

            if (targetCC == null ||
                FPCollide.GetDis2(targetCC.GetPos(), m_creature.GetPos()) > new FixedPoint(20 * 20) ||
                targetCC.IsDie())  // 隐藏时,不作为目标
            {
                targetUid = 0;
            }
            else
            {
                return(true);
            }

            targetUid = m_creature.GetTarget(lookDis);
            // 如果没有目标,检测玩家附近的单位,锁定目标
            //FixedPoint m_minDis2 = new FixedPoint(999999);
            //List<long> list = CCreatureMgr.GetCreatureList();
            //for (int i = 0; i < list.Count; i++)
            //{
            //    CCreature cc = CCreatureMgr.Get(list[i]);
            //    FixedPoint abDis2 = FPCollide.GetDis2(m_creature.GetPos(), cc.GetPos());
            //    if (abDis2 > new FixedPoint(lookDis * lookDis))
            //        continue;

            //    if (cc.IsDie() || cc.GetUid() == m_creature.GetUid())
            //        continue;
            //    //if (m_creature.bCamp(cc))
            //    //    continue;


            //    if (abDis2 < new FixedPoint(lookDis * lookDis))    // 如果目标在视线范围内
            //    {
            //        if (abDis2 < m_minDis2)
            //        {
            //            targetUid = (int)cc.GetUid();
            //            m_minDis2 = abDis2;
            //        }
            //    }
            //}

            if (targetUid != 0)
            {
                m_dataBase.SetData <int>((int)eAIParam.INT_TARGET_UID, targetUid);
                return(true);
            }
            //m_creature.DestoryDownUpSkill();  // 无目标,结束机枪
            return(false);
        }
Example #2
0
        /// <summary>
        /// 摇杆的场景指示器也只能主角自己有,并且是操作完成才发送指令
        /// </summary>
        private void OnSkillEvent(int index, eJoyStickEvent jsEvent, Vector2 m_delta, bool bCancel)
        {
            m_curSkillIndex    = index;
            m_curSkillJoyStick = jsEvent;
            CCreature master = CCreatureMgr.GetMaster();

            CSkillInfo sInfo = m_master.GetSkillByIndex(index);

            //if (sInfo == null || !sInfo.IsCanUse())
            //{
            //    Debug.Log(index + " 不可用" + jsEvent);
            //    return;
            //}


            if (jsEvent == eJoyStickEvent.Drag)
            {
                m_curSkillDir = new Vector3(m_delta.x, 0, m_delta.y);
                m_curSkillDir.Normalize();
            }

            if (jsEvent == eJoyStickEvent.Down)
            {
                m_bSkillCancel = false;

                skillInfo = sInfo.m_skillInfo;


                m_ui.m_cancelBtn.SetActiveNew(true);
                m_ui.SetColor(index, SKLL_BLUE);


                m_skillChose.gameObject.SetActiveNew(true);
                m_skillCenter.gameObject.SetActiveNew(true);
                m_skillDistance.gameObject.SetActiveNew(true);
                m_skillSectorDir.gameObject.SetActiveNew(false);
                m_skillDir.gameObject.SetActiveNew(false);
                m_skillPos.gameObject.SetActiveNew(false);

                m_skillDistance.localScale = new Vector3(skillInfo.distance, 0.01f, skillInfo.distance) * 2;
            }

            // 自己
            if (skillInfo.selectTargetType == (int)eSelectTargetType.Self)
            {
                m_curSkillDir = master.GetDir().ToVector3();
            }
            // 扇形方向
            else if (skillInfo.selectTargetType == (int)eSelectTargetType.SectorDir)
            {
                if (jsEvent == eJoyStickEvent.Down)
                {
                    m_curSkillDir = master.GetDir().ToVector3();
                    m_skillSectorDir.gameObject.SetActiveNew(true);
                    m_skillSectorDir.localScale = new Vector3(skillInfo.distance, 0.01f, skillInfo.distance);
                }
                else if (jsEvent == eJoyStickEvent.Drag)
                {
                }
                m_skillCenter.rotation = Quaternion.LookRotation(m_curSkillDir);  // 只用控制中心点的方向
            }
            // 直线方向
            else if (skillInfo.selectTargetType == (int)eSelectTargetType.Dir)
            {
                if (jsEvent == eJoyStickEvent.Down)
                {
                    int tUid = master.GetTarget(skillInfo.distance);
                    if (tUid == 0)
                    {
                        m_curSkillDir = master.GetDir().ToVector3();
                    }
                    else
                    {
                        CCreature cc = CCreatureMgr.Get(tUid);
                        if (cc != null)
                        {
                            m_curSkillDir = (cc.GetPos() - master.GetPos()).ToVector3().normalized;
                        }
                    }
                    m_skillDir.gameObject.SetActiveNew(true);
                    m_skillDir.localScale = new Vector3(skillInfo.distance, 0.01f, skillInfo.distance);
                }
                else if (jsEvent == eJoyStickEvent.Drag)
                {
                }
                m_skillCenter.rotation = Quaternion.LookRotation(m_curSkillDir);  // 只用控制中心点的方向
            }
            // 位置
            else if (skillInfo.selectTargetType == (int)eSelectTargetType.Pos)
            {
                if (jsEvent == eJoyStickEvent.Down)
                {
                    int tUid = master.GetTarget(skillInfo.distance);
                    if (tUid == 0)
                    {
                        m_curSkilPos = m_master.GetPos().ToVector3();
                    }
                    else
                    {
                        CCreature cc = CCreatureMgr.Get(tUid);
                        if (cc != null)
                        {
                            m_curSkilPos = cc.GetPos().ToVector3();
                        }
                    }
                    m_skillPos.gameObject.SetActiveNew(true);
                    m_skillPos.position   = m_curSkilPos;
                    m_skillPos.localScale = new Vector3(skillInfo.length, 0.001f, skillInfo.length);
                }
                else if (jsEvent == eJoyStickEvent.Drag)
                {
                    Vector3 atkOffset = m_curSkillDir * m_delta.magnitude * skillInfo.distance;
                    m_curSkilPos        = m_master.m_vCreature.GetEnt().GetPos() + atkOffset;
                    m_skillPos.position = m_curSkilPos;
                }
            }

            if (jsEvent == eJoyStickEvent.Up)
            {
                // 发送技能
                if (!m_bSkillCancel)
                {
                    m_bSkillCancel = true;
                    //Debug.Log("发送技能:" + skillInfo.id  + "dir:" + m_curSkillDir + " pos:" + m_curSkilPos);
                    CmdFspSendSkill cmd = new CmdFspSendSkill();
                    cmd.m_casterUid  = (int)m_master.GetUid();
                    cmd.m_skillIndex = m_curSkillIndex;
                    cmd.m_dir        = (new Vector2(m_curSkillDir.x, m_curSkillDir.z)).ToVector2d();
                    cmd.m_endPos     = (new Vector2(m_curSkilPos.x, m_curSkilPos.z)).ToVector2d();
                    master.SendFspCmd(cmd);

                    OnSkillSpeak(index);
                }
                // 还原指示器
                CancelSkill();

                m_skillChose.gameObject.SetActiveNew(false);
            }
        }