Example #1
0
        protected override int onExecute(TBTWorkingData wData)
        {
            BattleBehaviorWorkingData behaviorData = wData as BattleBehaviorWorkingData;
            float             deltaTime            = behaviorData.deltaTime;
            BattleUnit        source  = behaviorData.owner;
            AIBehaviorRequest request = behaviorData.request;
            Unit target = request.target;

            Vector2 ownerPos  = source.Get2DPosition();
            Vector2 targetPos = target.Get2DPosition();

            float attackRange = source.GetAttackRange();
            float distance    = (targetPos - ownerPos).magnitude;

            if (distance <= attackRange)
            {
                return(TBTRunningStatus.FINISHED);
            }

            float moveSpeed  = source.GetMoveSpeed();
            float detalTime  = behaviorData.deltaTime;
            float toForwardX = (targetPos.x - ownerPos.x) / distance;
            float toForwardZ = (targetPos.y - ownerPos.y) / distance;
            float newPosX    = ownerPos.x + detalTime * moveSpeed * toForwardX;
            float newPosZ    = ownerPos.y + detalTime * moveSpeed * toForwardZ;

            source.Set2DPosition(newPosX, newPosZ);
            //BattleLog.Log("【NOD_MoveTo】移动速度:{0} 当前位置:{1},{2} 目标位置:{3},{4} newPosX:{5} newPosZ:{6}}",
            //    moveSpeed.ToString(), ownerPos.x.ToString(),ownerPos.y.ToString(), targetPos.x.ToString(),targetPos.y.ToString()
            //    ,newPosX.ToString(),newPosZ.ToString());

            GameMsg.instance.SendMessage(GameMsgDef.Hero_MoveTo, new HeorMoveEventArgs()
            {
                id        = source.id,
                targetPos = new Vector3(newPosX, 0, newPosZ),
                forward   = new Vector3(toForwardX, 0, toForwardZ)
            });
            return(TBTRunningStatus.EXECUTING);
        }
Example #2
0
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionTimerContext thisContext = getContext <TBTActionTimerContext>(wData);

            if (thisContext.lastTime == INFINITY)
            {
                thisContext.lastTime = UnityEngine.Time.time;
            }

            bool checkTimerOver = (UnityEngine.Time.time >= thisContext.lastTime + m_elapseTime);

            if (checkTimerOver == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                TBTAction node = GetChild <TBTAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
 //-------------------------------------------------------------
 /// <summary>
 /// 评估该节点是否符合准入条件
 /// </summary>
 public bool Evaluate(/*in*/ TBTWorkingData wData)
 {
     return((_precondition == null || _precondition.IsTrue(wData)) && onEvaluate(wData));
 }
Example #5
0
 protected virtual void onTransition(TBTWorkingData wData)
 {
 }
Example #6
0
 protected virtual void onExit(TBTWorkingData wData, int runningStatus)
 {
 }
Example #7
0
 //--------------------------------------------------------
 // inherented by children-
 protected virtual void onEnter(/*in*/ TBTWorkingData wData)
 {
 }
Example #8
0
 //--------------------------------------------------------
 // inherented by children
 protected virtual bool onEvaluate(/*in*/ TBTWorkingData wData)
 {
     return(true);
 }
Example #9
0
 //--------------------------------------------------------
 // inherented by children-
 protected virtual void onEnter(/*in*/ TBTWorkingData wData)
 {
     TLogger.PROFILE("Enter Node" + this.ToString());
 }
Example #10
0
 protected virtual void onExit(TBTWorkingData wData, int runningStatus)
 {
     TLogger.PROFILE("Exit Node" + this.ToString());
 }
Example #11
0
 public override bool IsTrue(/*in*/ TBTWorkingData wData)
 {
     return(GetChild <TBTPrecondition>(0).IsTrue(wData) &&
            GetChild <TBTPrecondition>(1).IsTrue(wData));
 }
Example #12
0
 public override bool IsTrue(/*in*/ TBTWorkingData wData)
 {
     return(false);
 }
Example #13
0
 public abstract bool IsTrue(/*in*/ TBTWorkingData wData);
Example #14
0
 public int Update(TBTWorkingData wData)
 {
     return(onUpdate(wData));
 }
Example #15
0
 protected virtual int onExecute(TBTWorkingData wData)
 {
     TLogger.DEBUG("Excute Node" + this.ToString());
     return(TBTRunningStatus.FINISHED);
 }
Example #16
0
 public void Transition(TBTWorkingData wData)
 {
     onTransition(wData);
 }
Example #17
0
 protected T getUserContexData <T>(TBTWorkingData wData) where T : class, new()
 {
     return(getContext <TBTActionLeafContext>(wData).getUserData <T>());
 }
Example #18
0
 protected virtual int onUpdate(TBTWorkingData wData)
 {
     return(TBTRunningStatus.FINISHED);
 }
Example #19
0
 protected override void onExit(TBTWorkingData wData, int runningStatus)
 {
     //BattleLog.Log("【NOD_MoveTo】onExit");
 }