public override TaskStatus OnUpdate() { if (!bInitFinish) { InitData(); return(TaskStatus.Running); } if (targets == null || targets.Count == 0) { if (npc.outLog) { ConsoleEx.DebugError("all the emermy is dead"); } return(TaskStatus.Failure); } npc.data.btData.atkerID = 0; npc.data.btData.IsInBattle = false; //如果跑到最后一个目标点,赢了 if (index.Value >= targets.Count) { // param.cmdType = WarMsg_Type.Idle; // param.Sender = npc.UniqueID; // param.Receiver = npc.UniqueID; // npc.SendMsg (npc.UniqueID, param); npc.SendAnimMsg(WarMsg_Type.Stand); return(TaskStatus.Success); } pathFind.speed = npc.data.configData.speed; if (npc.mAnimState.canMove) { if (!pathFind.enabled) { pathFind.enabled = true; } if (pathFind != null && mTargetTrans != null) { pathFind.destination = mTargetTrans.position; } } //如果跑到了当前位置,或者当前目标死亡,切换下一个目标,返回true if (AITools.IsInRange(mTrans.position, 2, mTargetTrans.position) || !targets[index.Value].IsAlive) { index.Value++; } if (npc.mAnimState.STATE != NpcAnimState.Run) { npc.SendAnimMsg(WarMsg_Type.Running); } return(TaskStatus.Running); }
public override TaskStatus OnUpdate() { if (myHero.mAnimState.canMove) { pathFind.destination = mTargetTrans.position; } if (pathFind != null && !pathFind.enabled) { pathFind.enabled = true; } if (myHero.mAnimState.STATE != NpcAnimState.Run) { myHero.SendAnimMsg(WarMsg_Type.Running); } if (AITools.IsInRange(mTrans.position, 1, mTargetTrans.position)) { myHero.SendAnimMsg(WarMsg_Type.Stand); pathFind.enabled = false; myHero.data.btData.atkerID = 0; myHero.data.btData.IsInBattle = false; myHero.data.btData.btStatus = NPCBattle_Status.RestForBlood; return(TaskStatus.Success); } return(TaskStatus.Running); }
public override TaskStatus OnUpdate() { if (target == null) { SelTarget(); return(TaskStatus.Running); } //跑到塔下了 if (AITools.IsInRange(mTrans.position, distance, targetPos)) { myHero.SendAnimMsg(WarMsg_Type.Stand); myHero.data.btData.btStatus = NPCBattle_Status.None; pathFind.enabled = false; return(TaskStatus.Success); } if (pathFind != null && !pathFind.enabled) { pathFind.enabled = true; } if (myHero.mAnimState.STATE != NpcAnimState.Run) { myHero.SendAnimMsg(WarMsg_Type.Running); } if (myHero.mAnimState.canMove) { pathFind.destination = targetPos; } return(TaskStatus.Running); }
public override TaskStatus OnUpdate() { //如果建筑不能移动, if (npc.data.configData.moveable == Moveable.BeStatic) { return(TaskStatus.Success); } //如果对方死了,返回失败 if (!target.Value.IsAlive) { return(TaskStatus.Failure); } //如果进入技能范围,返回true if (AITools.IsInRange(mTrans.position, seekRange, mTargetTrans.position)) { pathFind.enabled = false; return(TaskStatus.Success); } if (!pathFind.enabled) { pathFind.enabled = true; } if (npc.mAnimState.canMove) { pathFind.destination = target.Value.transform.position; } if (npc.mAnimState.STATE != NpcAnimState.Run) { // param.cmdType = WarMsg_Type.Running; // param.Sender = npc.UniqueID; // param.Receiver = npc.UniqueID; // npc.SendMsg (npc.UniqueID, param); npc.SendAnimMsg(WarMsg_Type.Running); } return(TaskStatus.Running); }
//往家里跑 public override TaskStatus OnUpdate() { myHero.data.btData.btStatus = NPCBattle_Status.Fleeing; //如果跑到了,返回成功 if (AITools.IsInRange(mTran.position, 3, mTargetTran.position)) { if (pathFind != null && pathFind.enabled) { pathFind.enabled = false; } myHero.data.btData.btStatus = NPCBattle_Status.None; fleeTarget.Value = null; myHero.data.btData.atkerID = 0; myHero.data.btData.IsInBattle = false; return(TaskStatus.Success); } if (pathFind != null && !pathFind.enabled) { pathFind.enabled = true; } if (myHero.mAnimState.canMove) { pathFind.destination = mTargetTran.position; } if (myHero.mAnimState.STATE != NpcAnimState.Run) { myHero.SendAnimMsg(WarMsg_Type.Running); } return(TaskStatus.Running); }
// The agents will always be following the leader so always return running public override TaskStatus OnUpdate() { if (leader == null) { InitData(); } if (leader == null) { return(TaskStatus.Running); } var behindPosition = LeaderBehindPosition(); // Determine a destination for each agent bool arrive = true; for (int i = 0; i < agents.Length; ++i) { if (Vector3.SqrMagnitude(agentTransforms [i].position - leaderTransform.position) < leaderBehindDistance.Value) { if (agents [i].enabled) { agents [i].enabled = false; } if (agentsHero [i].mAnimState.STATE != NpcAnimState.Stand) { // param.cmdType = WarMsg_Type.Stand; // param.Sender = agentsHero [i].UniqueID; // param.Receiver = agentsHero [i].UniqueID; // agentsHero [i].SendMsg (agentsHero [i].UniqueID, param); agentsHero[i].SendAnimMsg(WarMsg_Type.Stand); } continue; } arrive = false; if (!agents [i].enabled) { agents [i].enabled = true; } // Get out of the way of the leader if the leader is currently looking at the agent and is getting close if (LeaderLookingAtAgent(i) && Vector3.SqrMagnitude(leaderTransform.position - agentTransforms[i].position) < aheadDistance.Value) { if (myHero.mAnimState.canMove) { agents[i].destination = agentTransforms[i].position + (agentTransforms[i].position - leaderTransform.position).normalized * aheadDistance.Value; } } else { // The destination is the behind position added to the separation vector if (myHero.mAnimState.canMove) { agents[i].destination = behindPosition + DetermineSeparation(i); } } if (myHero.mAnimState.STATE != NpcAnimState.Run) { // param.cmdType = WarMsg_Type.Running; // param.Sender = myHero.UniqueID; // param.Receiver = myHero.UniqueID; // myHero.SendMsg (myHero.UniqueID, param); myHero.SendAnimMsg(WarMsg_Type.Running); } } if (arrive) { return(TaskStatus.Success); } return(TaskStatus.Running); }
// Move towards the destination. Return success once we have reached the destination. Return failure if the destination has respawned and we no longer should be seeking it. // Will return running if we are currently seeking public override TaskStatus OnUpdate() { myHero.data.btData.btStatus = NPCBattle_Status.Seeking; if (myHero.data.configData.moveable == Moveable.BeStatic) { return(TaskStatus.Success); } if (!target.Value.IsAlive) { return(TaskStatus.Failure); } if (!navMeshAgent.enabled) { navMeshAgent.enabled = true; } if (myHero.mAnimState.canMove && myHero.mAnimState.STATE != NpcAnimState.Run) { // param.cmdType = WarMsg_Type.Running; // param.Sender = myHero.UniqueID; // param.Receiver = myHero.UniqueID; // myHero.SendMsg (myHero.UniqueID, param); myHero.SendAnimMsg(WarMsg_Type.Running); } // use the nav agent's destination position if we are on an alternate path or the target is null. We are using an alternate path if the previous path would have collided with // an object on defense. target will be null when we are seeking a position specified by the position variable var targetPosition = (alternatePath || target.Value == null ? navMeshAgent.destination : tgtPos); targetPosition.y = 1; // ignore y // we can only arrive if the path isn't pending var thisPosition = transform.position; thisPosition.y = targetPosition.y; // If the magnitude is less than the arrive magnitude then we have arrived at the destination if (AITools.IsInRange(thisPosition, myHero.ATKRange + myHero.data.configData.radius, navMeshAgent.destination)) { // If we arrived from an alternate path then switch back to the regular path if (alternatePath) { alternatePath = false; targetPosition = tgtPos; } else { // return success if we don't need to rotate to the target or we are already at the target's rotation // if (!rotateToTarget || transform.rotation == target.Value.transform.rotation) { // return TaskStatus.Success; // } return(TaskStatus.Success); // not done yet. still need to rotate // transform.rotation = Quaternion.RotateTowards(transform.rotation, target.Value.transform.rotation, rotationSpeed.Value * Time.deltaTime); } } // fail if the target moved too quickly in one frame. This happens after the target has been caught and respawns // float distance; // if (prevMagnitude * 2 < (distance = Vector3.SqrMagnitude(thisPosition - targetPosition))) { // return TaskStatus.Failure; // } // prevMagnitude = distance; // try not to head directly for a defensive object if (avoidDefeneUnits && (rayCollision(transform.position - transform.right * 1, targetPosition, out hit) || rayCollision(transform.position + transform.right * 1, targetPosition, out hit))) { // looks like an object is within the path. Avoid the object by setting a new destination towards the right of the object that we would have hit hitPoint = hit.point + transform.right * 3; // hitPoint.y = transform.position.y; hitPoint.y = 1; if (myHero.mAnimState.canMove) { navMeshAgent.destination = hitPoint; } // The avoid object may still be in the way even though we moved to the right of the object. If this is the case then move to the left and hope that works if (rayCollision(transform.position, navMeshAgent.destination, out hit)) { hitPoint = hit.point - transform.right * 4; // hitPoint.y = transform.position.y; hitPoint.y = 1; if (myHero.mAnimState.canMove) { navMeshAgent.destination = hitPoint; } } // remember that we are taking an alternate path to prevent the agent from jittering back and forth alternatePath = true; // var thisPosition = transform.position; // thisPosition.y = hitPoint.y; // prevMagnitude = Vector3.SqrMagnitude(thisPosition - hitPoint); } else if (navMeshAgent.destination != targetPosition) { // the target position has changed since we last set the destination. Update the destination // if (myHero.playHero.CanMove) if (myHero.mAnimState.canMove) { navMeshAgent.destination = targetPosition; } } return(TaskStatus.Running); }