Esempio n. 1
0
 protected override bool onEvaluate(TBTWorkingData wData)
 {
     BotWorkingData thisData = wData.As<BotWorkingData>();
     //thisData._Character.SetTargetEnemy(null);
     //return true;
     return thisData._Character.GetTargetEnemy() == null;
 }
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);
            float distToTarget             = TMathUtils.GetDistance2D(targetPos, currentPos);

            if (distToTarget < 1f)
            {
                thisData.entityTF.position = targetPos;
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                int     ret        = TBTRunningStatus.EXECUTING;
                Vector3 toTarget   = TMathUtils.GetDirection2D(targetPos, currentPos);
                float   movingStep = 0.5f * thisData.deltaTime;
                if (movingStep > distToTarget)
                {
                    movingStep = distToTarget;
                    ret        = TBTRunningStatus.FINISHED;
                }
                thisData.entityTF.position = thisData.entityTF.position + toTarget * movingStep;
                return(ret);
            }
        }
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            if (TMathUtils.IsZero((targetPos - currentPos).sqrMagnitude))
            {
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                Vector3 toTarget   = TMathUtils.GetDirection2D(targetPos, currentPos);
                Vector3 curFacing  = thisData.entityTF.forward;
                float   dotV       = Vector3.Dot(toTarget, curFacing);
                float   deltaAngle = Mathf.Acos(Mathf.Clamp(dotV, -1f, 1f));
                if (deltaAngle < 0.1f)
                {
                    thisData.entityTF.forward = toTarget;
                    return(TBTRunningStatus.FINISHED);
                }
                else
                {
                    Vector3 crossV      = Vector3.Cross(curFacing, toTarget);
                    float   angleToTurn = Mathf.Min(3f * thisData.deltaTime, deltaAngle);
                    if (crossV.y < 0)
                    {
                        angleToTurn = -angleToTurn;
                    }
                    thisData.entityTF.Rotate(Vector3.up, angleToTurn * Mathf.Rad2Deg, Space.World);
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
Esempio n. 4
0
            protected override void onEnter(TBTWorkingData wData)
            {
                AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

                thisData.entityAnimator.Play("walk");
                MoveToStatus = TBTRunningStatus.EXECUTING;
            }
Esempio n. 5
0
            protected override void onEnter(TBTWorkingData wData)
            {
                TurnToStatus = TBTRunningStatus.EXECUTING;
                AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

                thisData.entityAnimation.Play("Attack");
            }
Esempio n. 6
0
 public override bool IsTrue(TBTWorkingData wData)
 {
     BotWorkingData thisData = wData.As<BotWorkingData>();
     Vector3 targetPos = thisData._Character.GetTargetPos();
     Vector3 currentPos = thisData._Character.Head.transform.position;
     var dis = Vector3.Distance(targetPos, currentPos);
     return dis < thisData._Character.MoveMotion;
 }
Esempio n. 7
0
            protected override void onEnter(TBTWorkingData wData)
            {
                TurnToStatus = TBTRunningStatus.EXECUTING;
                AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

                thisData.entityTF.DOLookAt(WarriorAI.Instance.transform.position, 1.5f)
                .OnComplete(() => UpdateStatus());
            }
Esempio n. 8
0
            public override bool IsTrue(TBTWorkingData wData)
            {
                AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

                return(Vector3.Distance(
                           thisData.entityTF.position,
                           WarriorAI.Instance.transform.position) < 1.5f);
            }
        public override bool IsTrue(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            return(TMathUtils.GetDistance2D(targetPos, currentPos) < 1f);
        }
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            userData.attackingTime = DEFAULT_WAITING_TIME;
            thisData.entity.PlayAnimation("Attack");
        }
Esempio n. 11
0
 protected override bool onEvaluate(TBTWorkingData wData)
 {
     UnityEngine.Profiling.Profiler.BeginSample("NodeChase.onEvaluate");
     BotWorkingData thisData = wData.As<BotWorkingData>();
     UnityEngine.Profiling.Profiler.EndSample();
     //return false;
     return thisData._Character.GetTargetEnemy() != null;
 }
Esempio n. 12
0
 protected override void onEnter(TBTWorkingData wData)
 {
     BotWorkingData thisData = wData.As<BotWorkingData>();
     //Debugger.LogFormat("class={0}, method={1}", LogColor.Green, false, LogUtil.GetCurClassName(), LogUtil.GetCurMethodName());
     //GenerateTargetPos(thisData._Character.Head.transform.position, wData);
     _InWander = false;
     _CurSteerTime = _SteerGapTime;
     _CurCheckTime = _CheckGapTime;
 }
Esempio n. 13
0
            protected override int onExecute(TBTWorkingData wData)
            {
                AIEntityWorkingData thisData     = wData.As <AIEntityWorkingData>();
                Vector3             moveDistance = Vector3.Normalize(WarriorAI.Instance.transform.position - thisData.entityTF.position) * 0.1f;

                thisData.entityTF.DOMove(thisData.entityTF.position + moveDistance, Time.deltaTime)
                .OnComplete(() => UpdateStatus());
                return(MoveToStatus);
            }
Esempio n. 14
0
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

            if (thisData.entityAnimator)
            {
                thisData.entityAnimator.CrossFade("walk", 0.2f);
            }
        }
Esempio n. 15
0
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            userData.attackingTime = DEFAULT_WAITING_TIME;
            if (thisData.entityAnimator)
            {
                thisData.entityAnimator.CrossFade("attack", 0.2f);
            }
        }
Esempio n. 16
0
        public override bool IsTrue(TBTWorkingData wData)
        {
            bool result = false;

            EGuideNodeID currentLogicStepID = wData.As <GuideWorkingData>().GuideDynamicBB.GetValue <EGuideNodeID>(EGuideBBKey.LogicStepID, EGuideNodeID.GuideNodeID_None);

            result = currentLogicStepID == m_eGuideNodeID;

            TLogger.PROFILE("判断当引导ID(" + currentLogicStepID + ")是否与当前数据一致:" + result);

            return(result);
        }
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

            if (thisData.entity.IsDead)
            {
                thisData.entity.PlayAnimation("Reborn");
            }
            else
            {
                thisData.entity.PlayAnimation("Walk");
            }
        }
Esempio n. 18
0
    void GenerateTargetPos(Vector3 curPos, TBTWorkingData wData)
    {
        BotWorkingData thisData = wData.As<BotWorkingData>();
        _TargetPos = MapManager.instance.GetRandPosInRect(
            MathUtil.GetNextRandomRect(curPos, thisData._Character.VisualField, thisData._Character.Head.Radius * 2));
        //_TargetPos = MapManager.instance.GetRandPosInCurMap(ESpawnType.Character);
#if UNITY_EDITOR
        Debug.DrawLine(curPos, _TargetPos, Color.red, 1);
        //Debug.LogError("GenerateTargetPos Name=" + thisData._Character.Name + ", target pos=" + _TargetPos + ", NodeWander.HashCode=" + GetHashCode());
        //for test
        //var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //go.transform.position = _TargetPos;
#endif
    }
Esempio n. 19
0
 protected override int onExecute(TBTWorkingData wData)
 {
     UnityEngine.Profiling.Profiler.BeginSample("NodeChase.onExecute in");
     BotWorkingData thisData = wData.As<BotWorkingData>();
     Vector3 targetPos = thisData._Character.GetTargetPos();
     Vector3 currentPos = thisData._Character.Head.transform.position;
     float distToTarget = Vector3.Distance(targetPos, currentPos);
     UnityEngine.Profiling.Profiler.EndSample();
     if (distToTarget < thisData._Character.MoveMotion)
     {
         _CurSteerTime = 0;
         thisData._Character.SetTargetEnemy(null);
         return TBTRunningStatus.FINISHED;
     }
     else if (distToTarget > thisData._Character.VisualField)
     {
         thisData._Character.SetTargetEnemy(null);
         return TBTRunningStatus.FINISHED;
     }
     else
     {
         UnityEngine.Profiling.Profiler.BeginSample("NodeChase.onExecute else");
         var player = thisData._Character.GetTargetEnemy().GetComponent<BaseCharacter>();
         if (player != null && player.TotalLength >= thisData._Character.TotalLength)
         {
             thisData._Character.SetTargetEnemy(null);
             return TBTRunningStatus.FINISHED;
         }
         if (_CurSteerTime > 0)
         {
             _CurSteerTime -= thisData._DeltaTime;
         }
         else
         {
             _CurSteerTime = _SteerGapTime;
             Enemy bot = thisData._Character as Enemy;
             Debug.DrawLine(currentPos, targetPos, Color.green, 1);
             if (bot != null)
             {
                 bot.SteerToTargetPos(targetPos, () =>
                 {
                     thisData._Character.SetTargetEnemy(null);
                 }, null);
             }
         }
         //Debugger.LogFormat("NodeChase targetPos={0}", targetPos);
         UnityEngine.Profiling.Profiler.EndSample();
         return TBTRunningStatus.EXECUTING;
     }
 }
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            if (userData.attackingTime > 0)
            {
                userData.attackingTime -= thisData.deltaTime;
                if (userData.attackingTime <= 0)
                {
                    thisData.entityAnimator.SetInteger("DeadRnd", Random.Range(0, 3));
                    thisData.entity.PlayAnimation("Dead");
                    thisData.entity.IsDead = true;
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
Esempio n. 21
0
        public override bool IsTrue(TBTWorkingData wData)
        {
            bool result = false;

            if (m_nLogicStepID == -1)
            {
                result = false;
            }
            else
            {
                int currentLogicStepID = wData.As <GuideWorkingData>().GuideDynamicBB.GetValue <int>(EGuideBBKey.LogicStepID, -1);

                result = (currentLogicStepID != -1 && currentLogicStepID == m_nLogicStepID);

                TLogger.PROFILE("判断当前逻辑层的步骤ID(" + currentLogicStepID + ")是否与当前数据一致:" + result);
            }
            return(result);
        }
Esempio n. 22
0
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            if (userData.attackingTime > 0)
            {
                userData.attackingTime -= thisData.deltaTime;
                if (userData.attackingTime <= 0)
                {
                    if (thisData.entityAnimator)
                    {
                        thisData.entityAnimator.CrossFade(ENDING_ANIM[Random.Range(0, ENDING_ANIM.Length)], 0.2f);
                    }
                    return(TBTRunningStatus.FINISHED);
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
Esempio n. 23
0
        protected void UpdateLogicData(TBTWorkingData _data)
        {
            GuideWorkingData gData = _data.As <GuideWorkingData>();

            if (gData != null && m_nLogicStepID != gData.GuideDynamicBB.GetValue <int>(EGuideBBKey.LogicStepID, -1))
            {
                if (m_nLogicStepID != -1)
                {
                    Transition(_data);
                }
                m_nLogicStepID = gData.GuideDynamicBB.GetValue <int>(EGuideBBKey.LogicStepID, -1);

                GuideRoot_01Context thisContext = getContext <GuideRoot_01Context>(_data);

                thisContext.currentSelectedIndex++;
                if (!IsIndexValid(thisContext.currentSelectedIndex))
                {
                    thisContext.currentSelectedIndex = -1;
                }
            }
        }
Esempio n. 24
0
    protected override int onExecute(TBTWorkingData wData)
    {
        BotWorkingData thisData = wData.As<BotWorkingData>();
        //Debugger.LogErrorFormat("dis={0}, delta={1}, Name={2}, _TargetPos={3}, NodeWander.HashCode={4}",
        //Vector3.Distance(_TargetPos, thisData._Character.Head.transform.position), ConstValue._MinMoveDelta, thisData._Character.Name, _TargetPos, GetHashCode());
        //Debugger.LogGreen("curtime=" + _CurSteerTime);
        Vector3 targetPos = _TargetPos;
        Vector3 currentPos = thisData._Character.Head.transform.position;
        float distToTarget = Vector3.Distance(targetPos, currentPos);
        if (distToTarget < thisData._Character.MoveMotion)
        {
            if (_InWander)
            {
                //Debugger.LogFormat("reach dest class={0}, method={1}", LogColor.Blue, false, LogUtil.GetCurClassName(), LogUtil.GetCurMethodName());
                _CurSteerTime = _SteerGapTime;
                _InWander = false;
                _LastStepPoses.Clear();
            }
        }

        // check enemy operation has a cool down time. 
        if (_CurCheckTime > 0)
        {
            _CurCheckTime -= thisData._DeltaTime;
        }
        else
        {
            UnityEngine.Profiling.Profiler.BeginSample("NodeWander.onExecute CheckEnemy");
            _CurCheckTime = _CheckGapTime;
            var player = (thisData._Character as Enemy);
            if (player != null)
            {
                player.CheckEnemy();
            }
            UnityEngine.Profiling.Profiler.EndSample();
            //Debugger.LogFormat("check enemy class={0}, method={1}", LogColor.Brown, false, LogUtil.GetCurClassName(), LogUtil.GetCurMethodName());
        }

        // wait for next wander command
        if (_CurSteerTime > 0)
        {
            _CurSteerTime -= thisData._DeltaTime;
        }
        else
        {
            if (!_InWander)
            {
                //Debugger.LogFormat("generate pos class={0}, method={1}", LogColor.Cyan, false, LogUtil.GetCurClassName(), LogUtil.GetCurMethodName());
                GenerateTargetPos(thisData._Character.Head.transform.position, wData);
                _InWander = true;
            }
        }

        if (_InWander)
        {
            //Debugger.LogFormat("steer to class={0}, method={1}", LogColor.Green, false, LogUtil.GetCurClassName(), LogUtil.GetCurMethodName());
            UnityEngine.Profiling.Profiler.BeginSample("NodeWander.onExecute InWander");
            var motion = (_TargetPos - thisData._Character.Head.transform.position).normalized
                * thisData._Character.MoveSpeed * Singleton._DelayUtil.Timer.DeltaTime;
            bool rs = thisData._Character.Move(motion);
            if (!rs)
            {
                if (_InWander)
                {
                    _CurSteerTime = _SteerGapTime;
                    _InWander = false;
                    _LastStepPoses.Clear();
                }
            }

            if (_LastStepPoses.Count == _MaxRecordStepCount)
            {
                int nearCount = 0;
                foreach (var item in _LastStepPoses)
                {
                    if (Vector3.Distance(item, thisData._Character.Head.transform.position) < thisData._Character.MoveMotion / 2f)
                    {
                        nearCount += 1;
                    }
                }
                if (nearCount >= 2)
                {
                    //Debug.LogErrorFormat("nearCount name={0}, peek={1}, dist={2}, delta={3}",
                    //    _Character.Name, _LastStepPoses.Peek(),
                    //    Vector3.Distance(_LastStepPoses.Peek(), _Character.Head.transform.position),
                    //    _Character.MoveMotion);
                    if (_InWander)
                    {
                        _CurSteerTime = _SteerGapTime;
                        _InWander = false;
                        _LastStepPoses.Clear();
                    }
                }
            }
            Assert.IsTrue(_LastStepPoses.Count <= _MaxRecordStepCount);
            if (_LastStepPoses.Count == _MaxRecordStepCount)
            {
                _LastStepPoses.Dequeue();
            }
            _LastStepPoses.Enqueue(thisData._Character.Head.transform.position);

            UnityEngine.Profiling.Profiler.EndSample();
        }
        return TBTRunningStatus.EXECUTING;
    }
Esempio n. 25
0
            protected override void onEnter(TBTWorkingData wData)
            {
                AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

                thisData.entityAnimation.Play("idle");
            }
Esempio n. 26
0
        protected override int onExecute(TBTWorkingData wData)
        {
            wData.As <GuideWorkingData>().GuideDynamicBB.SetValue(EGuideBBKey.LogicStepID, m_eGuideNodeID);

            return(base.onExecute(wData));
        }