public Character Refresh(excel_refresh refreshExcel, Scene scn) { int index = Mathf.RandRange(0, refreshExcel.birthpoint.Length - 1); string birthPointName = refreshExcel.birthpoint[index]; MarkPoint markPoint = GetMarkPoint(scn.ScnID, birthPointName); if (markPoint == null) { return(null); } Vector3 targetPos = markPoint.position; Vector3 dir = new Vector3(Mathf.RandRange(-1.0f, 1.0f), 0.0f, Mathf.RandRange(-1.0f, 1.0f)); dir.Normalize(); float dist = Mathf.RandRange(0.0f, 1.0f) * refreshExcel.refreshDist; targetPos += (dist * dir); Vector3 hitPos = Vector3.zero; uint layer = NavigationSystem.GetLayer(markPoint.position); if (NavigationSystem.LineCast(markPoint.position, targetPos, layer, out hitPos)) { targetPos = hitPos; } float h = 0.0f; if (NavigationSystem.GetLayerHeight(targetPos, layer, out h)) { targetPos.y = h; } NPC npc = new NPC(); return(npc); }
static void ResetTargePos(Character cha, ChildObject childObject, SkillContext context, excel_skill_event e) { SkillSelectCharactorType selType = (SkillSelectCharactorType)e.evnetParam1; Character selTarget = context.SelectCharactorByType(selType); if (selTarget == null) { return; } float fAngle = (float)e.evnetParam2; if (e.evnetParam3 > 0) { float fAngleR = (float)e.evnetParam3 * 2.0f; float fPct = UnityEngine.Random.Range(0.0f, 1.0f); fAngle += fPct * fAngleR - fAngleR; } Quaternion q = Quaternion.AngleAxis(fAngle, Vector3.up); Vector3 dir = selTarget.Direction; if (e.evnetParam4 > 0 && context.mOwner != selTarget) { dir = selTarget.Position - context.mOwner.Position; dir.y = 0.0f; dir.Normalize(); } dir = q * dir; float dist = (float)e.evnetParam5 * 0.001f; Vector3 targetPos = selTarget.Position + dir * dist; TargetPosTestType testType = (TargetPosTestType)e.evnetParam6; switch (testType) { case TargetPosTestType.None: break; case TargetPosTestType.LineTest: { uint layer = NavigationSystem.GetLayer(context.mOwner.Position); if (NavigationSystem.LineCast(context.mOwner.Position, targetPos, layer, out targetPos)) { break; } break; } case TargetPosTestType.TargetInNav: { if (!NavigationSystem.IsInNavigation(targetPos)) { targetPos = selTarget.Position; } break; } } context.TargetPos = targetPos; }
public void LineMove(Vector3 pos, float destRadius = 0.3f, bool sync = true) { Vector3 destPos; if (!NavigationSystem.LineCast(Position, pos, NavLayer, out destPos)) { return; } mPath = new Vector3[1] { destPos }; mCurrentNodeIndex = 0; MoveSpeed = 0.0f; mDestRadius = destRadius; }
void DoPatrol() { if (mNPC.mRefreshList == null) { return; } int npcAIID = mNPC.mRefreshList.npcAI; excel_npc_ai npcAI = excel_npc_ai.Find(npcAIID); if (npcAI == null) { return; } if (NormalBehaviourPhase.PatrolInterval == mPhase) { mIntervalTime -= Time.DeltaTime; if (mIntervalTime > 0.0f) { return; } PatrolType patrolType = (PatrolType)npcAI.patrolType; if (patrolType == PatrolType.Scope) { if (mNPC.mRefreshList.birthpoint.Length <= 0) { return; } string birthpoint = mNPC.mRefreshList.birthpoint[0]; MarkPoint markPoint = RefreshSystem.Instance.GetMarkPoint(mNPC.mScene.ScnID, birthpoint); if (markPoint == null) { return; } Vector3 targetPos = markPoint.position; Vector3 dir = new Vector3(Mathf.RandRange(-1.0f, 1.0f), 0.0f, Mathf.RandRange(-1.0f, 1.0f)); dir.Normalize(); float dist = Mathf.RandRange(0.0f, 1.0f) * npcAI.patrolRadius; targetPos += (dist * dir); Vector3 hitPos = Vector3.zero; if (NavigationSystem.LineCast(mNPC.Position, targetPos, mNPC.mNavLayer, out hitPos)) { targetPos = hitPos; } mPath = new Vector3[1]; mPath[0] = targetPos; mPathIndex = 0; mPhase = NormalBehaviourPhase.Patrol; } } else if (NormalBehaviourPhase.Patrol == mPhase) { if (mPath == null || mPathIndex >= mPath.Length) { mIntervalTime = Mathf.RandRange(npcAI.patrolMinInterval, npcAI.patrolMaxInterval); mPhase = NormalBehaviourPhase.PatrolInterval; return; } Vector3 targetPos = mPath[mPathIndex]; if (!mNPC.IsSearchMoving()) { mNPC.SearchMove(targetPos); } float dist = (targetPos - mNPC.Position).Length(); if (dist <= 0.3f) { ++mPathIndex; } } }