// ReSpawn public bool ReSpawn() { if (stat == null) { return(false); } stat.ReSpawn(); state = eNPCState.FollowPath; pathFinder.bReachPoint = true; pathFinder.FindNewPath(this.transform.position); switch (Random.Range(1, 3)) { case 1: weaponType = Weapon.eWeaponType.Gun; break; case 2: weaponType = Weapon.eWeaponType.Rifle; break; case 3: weaponType = Weapon.eWeaponType.Shotgun; break; } weapon.SetWeaponWithType(weaponType); ChangeSprite(weaponType); npcRoTTarget.target = null; return(true); }
protected virtual bool InitTplData(IActorInitBase initBase) { var init = initBase as NpcInit; if (null == init) { return(false); } mNpcData.TemplateId = init.Data.tid; if (null == NPCData.Template) { return(false); } mNpcData.RoleName = NPCData.Template.name; mDeadBodyTime = mNpcData.Template.deadBodyTime; SkillMgr.Init(this, mNpcData); mCurrentSpellID = SkillMgr.getElementByIndex(0).ID; mCastSpellDistance = NPCData.Template.distance; mSpellType = (ushort)eSkillTargetType.Enemy; BaseGameLogic <INPCLogic> bgLogic = (BaseGameLogic <INPCLogic>)GameLogicManager.Instance.GetGameLogic(eGameLogicType.NPCLogic, (short)mNpcData.Template.logic); if (null != bgLogic) { mLogic = bgLogic.Logic; } mState = eNPCState.Idle; return(true); }
public void ChangeState(eNPCState state) { if (IsDie && mState != eNPCState.None && state != eNPCState.Dead) { return; } if (mState == state) { return; } if (state == eNPCState.ReturnSpawnPoint) { mAttackTarget = 0; PlayerStatus.AddStatusType((int)eBuffStatusType.无敌); //开启无敌模式 } else if (mState == eNPCState.ReturnSpawnPoint) { PlayerStatus.DelStatusType((int)eBuffStatusType.无敌); //关闭无敌模式 } mState = state; mStateLastTime = 0; switch (mState) { case eNPCState.Idle: case eNPCState.Patrol: case eNPCState.ReturnSpawnPoint: SetBattleStatus(false); break; case eNPCState.FollowTarget: case eNPCState.CastSpell: case eNPCState.WaitCoolDown: case eNPCState.Dead: case eNPCState.FixedBody: SetBattleStatus(true); break; } //不是巡逻,追击,回出生点,移动停下来 if (mState != eNPCState.Patrol && mState != eNPCState.FollowTarget && mState != eNPCState.ReturnSpawnPoint && mState != eNPCState.Transport && mState != eNPCState.Pause) { CleanMoveNodes(); } }
//===================================================== private void ExitState(eNPCState npcStateExited) { if (_currentJobs == null || _currentJobs.Count <= 0) { return; } foreach (var job in _currentJobs) { if (job != null) { job.Kill(); } } // Clear jobs list _currentJobs.Clear(); }
public virtual void OnDead() //躺尸 { if (!IsDie) { return; } if (mStateLastTime >= mNpcData.Template.deadBodyTime * 1000) { mState = eNPCState.None; if (InMapData.rebornTime == 0) { OnTimeReborn(new TimerEvent(HostMap)); } else if (InMapData.rebornTime > 0) { TimerManager.doOnce(InMapData.rebornTime, OnTimeReborn, HostMap); } OnLeaveMap(); } }
//===================================================== #region State Controllers private void EnterState(eNPCState npcStateEntered) { //_triggerTargetInRange.SetActive( true ); switch (npcStateEntered) { case eNPCState.INIT: _thisNavMeshObstacle.enabled = false; _thisAgent.enabled = true; _thisRigidbody.isKinematic = true; // Delay then GATHER - delay ensures jobs are added to JobManager correctly StartCoroutine(Initialising()); break; case eNPCState.IDLE: // ToDo: do something Debug.Log("NPC Idle!"); _thisAgent.enabled = false; //_thisNavMeshObstacle.enabled = true; break; case eNPCState.WALK: // ToDo: DEBUG - REMOVE THIS //_debugStateRenderer.material.color = Color.green; //Debug.Log( "NPC Walk!" ); // Assign jobs _walking = new Job(Walking(() => { Debug.Log("Met NPC. Talking!"); CurrentState = eNPCState.TALK; }), true); //_looking = new Job( Looking( 150.0f, _triggerTargetRadius, 0.33f, false, // () => // { // if( GameDataManager.Instance.IsPlayerHealthFull() == true || IsPlayerAttackOk() == false ) // { // //Debug.Log( "Saw player. Run!" ); // CurrentState = eEnemyState.ESCAPE; // } // else // { // //Debug.Log( "Saw player. Attack!" ); // CurrentState = eEnemyState.HUNT; // } // } ), // true ); // Update jobs list _currentJobs.Add(_walking); //_currentJobs.Add( _looking ); break; case eNPCState.ATTRACT: // ToDo: DEBUG - REMOVE THIS //_debugStateRenderer.material.color = Color.blue; //Debug.Log( "NPC Attract!" ); // Assign jobs _attracting = new Job(Attracting(() => { //Debug.Log( "Attracting attention!" ); CurrentState = eNPCState.WALK; }), true); // Update jobs list _currentJobs.Add(_attracting); break; case eNPCState.TALK: // ToDo: DEBUG - REMOVE THIS //_debugStateRenderer.material.color = Color.yellow; //Debug.Log( "NPC Talk!" ); _thisAgent.enabled = false; _thisNavMeshObstacle.enabled = true; // Assign jobs //_escaping = new Job( Escaping( () => //{ // //Debug.Log( "Escaped player. Phew!" ); // CurrentState = eEnemyState.POST_ESCAPE; //} ), // true ); //// Update jobs list //_currentJobs.Add( _escaping ); break; case eNPCState.DEAD: // Do nothing break; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { pause = !pause; } if (pause) { return; } speedScale = 1; //Function IsLostTarget()////////////////// if (npcRoTTarget.target != null) { lostTarget = false; tempLostTarget = false; timeLostTargetCount = timeLostTarget; } else { tempLostTarget = true; } // Khi vào trạng thái theo dấu mục tiêu(FollowTarget) thì bắt đầu đếm thời gian để quyết định mất dấu mục tiêu if (!lostTarget && tempLostTarget) { timeLostTargetCount -= Time.deltaTime; } if (timeLostTargetCount < 0) { lostTarget = true; } /////////////////////////////////////////// // Đoạn này chắc đọc code hiểu thoy switch (state) { case eNPCState.Idle: break; case eNPCState.FollowPath: if (npcRoTTarget.target != null) { state = eNPCState.FireTarget; } nextPosition = pathFinder.FollowPath(this.transform.position, stat.speed, obstacleMask); velocity = (nextPosition - transform.position).normalized; if (pathFinder.bReachPoint) { pathFinder.FindNewPath(this.transform.position); } //Wandering npcRoTTarget.RotateToPosition(nextPosition); break; case eNPCState.FollowTarget: if (lostTarget) { state = eNPCState.FollowPath; } if (!tempLostTarget) { state = eNPCState.FireTarget; } nextPosition = pathFinder.FollowPath(this.transform.position, LostLocation, stat.speed, obstacleMask); velocity = (nextPosition - transform.position).normalized; if (pathFinder.bReachPoint) { timeLostTargetCount = -1; pathFinder.FindNewPath(this.transform.position); } //npcRoTTarget.RotateToPosition(nextPosition); break; case eNPCState.FireTarget: if (tempLostTarget) { if (level == eNPCLevel.Easy) { state = eNPCState.FollowPath; } else { state = eNPCState.FollowTarget; } } if (npcRoTTarget.target != null) { LostLocation = npcRoTTarget.target.transform.position; } UpdateFireState(); break; } if (state != eNPCState.FireTarget) { ObstacleAvoidance(); npcRoTTarget.RotateToPosition(nextPosition); this.transform.position += transform.TransformDirection(Vector3.up) * stat.speed; } else { this.transform.position = nextPosition; } }